在我的页面中,有几个输入和选择标签.
我用宽度:100%;定义它们的宽度,但浏览器中的宽度不是100%.
我在chrome中使用了调试工具,发现还应用了useragent样式表样式.
如何使宽度100%?
解决方法
Demo Fiddle
input,select{ width:100%; Box-sizing:border-Box; }
NB. demo fiddle without box-sizing set
并且您需要使用Box-sizing:border-Box来调整大小以考虑任何特定于浏览器或设置边距/填充/边框. Here’s a handy read on the subject.
The Box-sizing CSS property is used to alter the default CSS Box model
used to calculate widths and heights of elements. It is possible to
use this property to emulate the behavior of browsers that do not
correctly support the CSS Box model specification.border-Box
The width and height properties include the padding and border,but not the margin. This is the Box model used by Internet Explorer when the document is in Quirks mode.