I am trying to vertically center one div (containing a search bar) inside another (a top banner). I was under the impression that to do so you did the following:
#banner {
height: 35px;
width: 100%;
}
#searchbar {
height: 15px;
position: relative;
top: 50%;
margin-top: -7.5px; /* half of the height */
}
This works fine until you add the margin-top at which point it is applied to the #banner as well.
Is there an alternative way to do this, or am I just doing it wrong?
I use
line-heightwith the value being the same as height of parent div.As seen here: http://jsfiddle.net/vkJ78/24/
CSS:
EDIT: Per recommendation from NGLN, this will also fix horizontal centering,
#srcdivand#srchaving equal widths.