html – 如何在css中进行输入并选择相同的宽度

前端之家收集整理的这篇文章主要介绍了html – 如何在css中进行输入并选择相同的宽度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的页面中,有几个输入和选择标签.

我用宽度:100%;定义它们的宽度,但浏览器中的宽度不是100%.

我在chrome中使用了调试工具,发现还应用了useragent样式表样式.

如何使宽度100%?

解决方法

Demo Fiddle

理想情况下,您应该将样式与内容分开,因此在CSS中包括

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.

Box-Sizing on MDN:

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.

猜你在找的HTML相关文章