为什么添加一些 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/