微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/html/226465.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐