html - 如何使元素宽度为 : 100% minus padding?

标签 html css width fluid-layout

我有一个 html 输入。

输入有 padding: 5px 10px; 我希望它是父 div 宽度的 100%(流动)。

但是使用 width: 100%; 会导致输入为 100% + 20px 我该如何解决这个问题?

Example

最佳答案

box-sizing: border-box是一种快速、简单的修复方法:

这个 will work in all modern browsers , 和 IE8+。

这是一个演示:http://jsfiddle.net/thirtydot/QkmSk/301/

.content {
    width: 100%;
    box-sizing: border-box;
}

现代浏览器不需要浏览器前缀版本(-webkit-box-sizing 等)。

关于html - 如何使元素宽度为 : 100% minus padding?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5219175/

相关文章:

html - 使用 bootstrap 创建标题图像

css - Angular Material cdk-container 和主站点固定标题 z-index 覆盖

html - CSS div 填充没有位置的整个父级 :absolute

CSS 大多数带有百分比值的参数。好的做法?

css - 有没有办法将字体 Awesome Icon 的高度和宽度设置为其父容器的完整宽度和高度?

javascript - 使用 JavaScript 设置 cookie 并获取 cookie

javascript - 没有巨大的行间距不能垂直对齐多行

html - 与表单控件类相关的类在 bootstrap 4 中无法正常运行

Javascript:避免多个弹出框/检查div是否为空

HTML 滚动条宽度