Is there an easy way to align a label with a textbox in all major browsers (i.e. including IE7? I set display to inline-block on my label and textbox which seems to work everywhere but in IE7, where the label is on the bottom of the div.
<label class="inputLabel" for="emailTextBox">
Email:</label>
<input class="textBox" type="text" id="emailTextBox" value=" Email address" />
input.textBox
{
margin-top: 5px;
margin-bottom: 5px;
height: 30px;
width: 350px;
font-size: 15px;
font-family: Verdana;
line-height: 30px;
display:inline-block;
}
label.inputLabel
{
font-family: Verdana;
font-size: 15px;
line-height: 30px;
display:inline-block;
}
The display:inline-block
declaration is not fully supported by IE7 and below, so you have to use display:inline
instead in conjunction with the zoom:1
hasLayout hack to imitate the declaration with the star hack to target IE7. To align both the textbox and labelwe can use the vertical-align:middle
property, like so:
CSS
input.textBox {
margin-top: 5px;
margin-bottom: 5px;
height: 30px;
width: 350px;
font-size: 15px;
font-family: Verdana;
line-height: 30px;
display:inline-block;
*display: inline; /* for IE7*/
zoom:1; /* for IE7*/
vertical-align:middle;
}
label.inputLabel {
font-family: Verdana;
font-size: 15px;
line-height: 30px;
display:inline-block;
*display: inline; /* for IE7*/
zoom:1; /* for IE7*/
}
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With