加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 18:25:48 所属栏目:资源 来源:网络整理
导读:在我的页面中,有几个输入和选择标签. 我用宽度:100%;定义它们的宽度,但浏览器中的宽度不是100%. 我在chrome中使用了调试工具,发现还应用了useragent样式表样式. 如何使宽度100%? 解决方法 Demo Fiddle 理想情况下,您应该将样式与内容分开,因此在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读