10

我设置高度:

input,select{height: 20px;}

但是在浏览器中它的高度是input : 20pxand select 18px,我不知道为什么,因为在输入和选择之前被重置。如果我删除<!DOCTYPE html>然后是好的,但是 IE 没有居中页面。

4

2 回答 2

12

这可以通过将box-sizing元素的属性设置为来纠正border-box

input, select{
  box-sizing: border-box;
}

供应商特定的前缀喜欢moz-webkit-可能适用。

于 2012-12-01T17:26:30.417 回答
2

I was able to set the height of my SELECT to exactly what I wanted in IE8 and 9. The trick is to set the box-sizing property to content-box. Doing so will set the content area of the SELECT to the height, but keep in mind that margin, border and padding values will not be calculated in the width/height of the SELECT, so adjust those values accordingly.

select {
    display: block;
    padding: 6px 4px;
    -moz-box-sizing: content-box;
    -webkit-box-sizing:content-box;
    box-sizing:content-box;
    height: 15px;
}

Here is a working jsFiddle. Would you mind confirming and marking the appropriate answer?

于 2013-01-02T15:43:00.697 回答