简体   繁体   English

IE7垂直对齐“内联”元素

[英]IE7 align vertically “inline” elements

I've a problem with IE7.. I added padding to my inputs (top and bottom). 我在IE7上有问题。我在输入(顶部和底部)中添加了填充。 In Firefox and others, the label shows in the middle, but in IE7, it shows at the bottom.. and in IE8, at the top. 在Firefox和其他版本中,标签显示在中间,但在IE7中,标签显示在底部。在IE8中,标签显示在顶部。

I tried to set label vertical-align:middle style, but it doesn't work. 我试图将标签设置为vertical-align:middle样式,但是它不起作用。

Its fiddle: http://jsfiddle.net/w2wTA/4/ 它的提琴: http : //jsfiddle.net/w2wTA/4/

Try setting a height for the 'field' div, and setting the line-height attribute equal to that: 尝试为“字段” div设置line-height ,并将line-height属性设置为等于该line-height

#field {
    height: 40px;
    line-height: 40px;
}

edit 编辑

You could also try adding a class to both the label and the input, setting the padding: 您也可以尝试将一个类添加到标签和输入中,并设置填充:

<div id="field">
    <label for="t" class="t">Input:</label> <input type="text" id="t" class="t">
</div>

css: (somehow, inline-block is not working, so block with a float will do the trick, though I find this a bit of a 'dirty hack') css :(以某种方式,内联块不起作用,因此使用浮点数的块将达到目的,尽管我发现这有点“肮脏”)

.t{
    padding: 10px 0;
}

label{
    vertical-align: middle;
    display: block;
    float: left;
}

This seems to work. 这似乎有效。 Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM