我读到设置元素的填充属性会同时增加元素的高度和宽度。当用于未嵌套在任何其他元素内的元素时,这是正确的。但是一旦我设置了一个嵌套元素的填充属性,比如说一个嵌套在一个div中的段落,只有那个嵌套元素的高度增加而宽度保持不变。它不应该增加宽度吗?另外当我指定非常嵌套元素的填充值很大,它会扩展到容器元素之外。有人可以向我解释这种行为吗?
最佳答案
您必须在 google 中搜索 CSS BOX 模型吗?
The padding area extends the content area with the empty area between the content and the eventual borders surrounding it. It often has a background, a color or an image (in that order, an opaque image hiding the background color), and is located inside the padding edge. Its dimensions are the padding-box width and the padding-box height.
The space between the padding and the content edge can be controlled using the padding-top, padding-right, padding-bottom, padding-left and the shorthand padding CSS properties.
关于html - padding 属性如何影响子元素的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18573414/