html - padding 属性如何影响子元素的宽度和高度?

标签 html css

我读到设置元素的填充属性会同时增加元素的高度和宽度。当用于未嵌套在任何其他元素内的元素时,这是正确的。但是一旦我设置了一个嵌套元素的填充属性,比如说一个嵌套在一个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.

https://developer.mozilla.org/en-US/docs/Web/CSS/box_model

关于html - padding 属性如何影响子元素的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18573414/

相关文章:

css - *zoom 和 zoom 有什么区别?

html - 移动浏览器上奇怪的 CSS '' 叠加效果''

javascript - 当form在IE11中定位一个html并操作另一个html时,它最后打开两个页面

css - 以小浏览器分辨率垂直居中 Flash 网站

html - 我想将 <ul> 按钮居中,但就是做不到

javascript - 简化每个ID的多项功能

CSS 表格宽度 : something missing?

html - 响应式标题图片的任何其他技术

javascript - 在 jquery 中向下滚动页面时隐藏内容

javascript - 使用 Jquery 使绝对按钮具有粘性动画