html - 在 DIV 内填充

标签 html css

为什么添加一些 padding 会影响 DIV 框外的元素?填充不应该在 DIV 的边界和 inside 的内容之间创建一些空间?如何在不影响 DIv 框外的元素的情况下创建这个空间?

最佳答案

How can you create this space without affecting elements outside the DIv box?

使用 box-sizing: border-box

来自 MDN :

border-box The width and height properties include the padding and border, but not the margin.

必须设置此属性的原因是 box-sizing 的默认值是 content-box。再次来自 MDN:

content-box This is the default style as specified by the CSS standard. The width and height properties are measured including only the content, but not the padding, border or margin.

关于html - 在 DIV 内填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34633024/

相关文章:

javascript - 使用输入 javascript 更改某个值?

html - 在图像上悬停显示一个带有表单的 div 区域

html - 强制图像左对齐

java - 形状的 CSS 不适用于 javafx 中的文本区域

html - 防止在文本框中滚动

javascript - 简单数学计算表单脚本中未捕获的 ReferenceError

html - 表行跨度单元格跨度

css - 使用 Gulp 保留原始文件

css - 如何增加内部具有绝对定位元素的元素的高度

html - 为什么文字装饰: none not work inside p?