html - padding增加div的宽度和高度

标签 html css

如何修改这些 div,以便当我更改它们的填充时,它们的高度和宽度不会扩展?我已经尝试实现了

.outer, .inner {
    display: block;
}

.outer {
    /* specify fixed width */
    width: 300px;
    padding: 0;
}

.inner {
    /* specify padding, can be changed while remaining fixed width of .outer */
    padding: 5px;
}

来自 here

通过给父 div fixed_widthrelative_container width:700px;height:100px; padding:0px;,但是当我将填充应用到 .content.obscure 时,div 会扩展以覆盖下面的 .extra_margins .谢谢!

http://jsfiddle.net/loren_hibbard/ZmJ9R/

最佳答案

您可以使用 CSS3 box-sizing 属性来执行此操作:

box-sizing: border-box;

http://css-tricks.com/box-sizing/

在 IE8+ 中支持,但某些浏览器可能需要前缀:

http://caniuse.com/css3-boxsizing

关于html - padding增加div的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13255311/

相关文章:

html - Meteor:访问each 语句中的模板助手

c# - 移至样式表时布局困惑

javascript - 如何在Bootstrap中设置默认选项卡

javascript - Bootstrap Alert 不会再次显示

html - YouTube 嵌入式视频高度仅在 IE9 中较短

javascript - angularjs 指令中的按钮不起作用

php - 我正在 laravel 中开发注册表单,但是当单击提交按钮时,它不会重定向到我的登录页面,这是为什么?

jquery - 按时更改图像不起作用(无法找到导致它的原因)

html 表格元素与上面的行不对齐

angular - 将 flex 规则应用于多个 Angular 4 组件的通用解决方案