内联元素的填充
我正在读一本关于CSS基础知识的书。在书中据称,内联元素具有完整的填充属性,但没有保证金顶/底部属性,只有 linf-left/right 属性。
我的第一个问题是,我在哪里可以将其作为官方声明?我发现在这里设置为auto
,然后将其设置为0
。但是,这与说保证金顶/底部不适用于内联元素并不不同吗?
我的第二个问题是,内联元素真的获得完整的填充属性吗?我尝试了以下示例:
<!DOCTYPE html>
<html>
<head> </head>
<body>
<div style="margin: 20px; border: solid 20px;background: red;">
<p style="margin:0">
test test test test test test test test test test test test test test test test test test test test test test test test
<strong style="padding:20px;background-color:yellow">hello</strong> test test test test
</p>
</div>
</body>
</html>
现在,这表明填充物实际上有效,但是由于某种原因,padding-top
和padding bottom
对周围文本没有影响。这是为什么? W3标准中的任何地方都提到过吗?
I am reading a book about CSS basics. It is claimed in the book that an inline element has complete padding properties but no margin-top/bottom properties, only margin-left/right properties.
My first question is, where can I find this as an official statement? I found here that if margin-top/bottom is set to auto
then it is set to 0
. But isn't that different from saying margin-top/bottom does not apply to inline-elements?
My second question is, does an inline element really got complete padding properties? I tried the following example:
<!DOCTYPE html>
<html>
<head> </head>
<body>
<div style="margin: 20px; border: solid 20px;background: red;">
<p style="margin:0">
test test test test test test test test test test test test test test test test test test test test test test test test
<strong style="padding:20px;background-color:yellow">hello</strong> test test test test
</p>
</div>
</body>
</html>
Now, this shows that padding actually works somehow, but for some reason, padding-top
and padding-bottom
has no effect on the surrounding text. Why is that? Is this mentioned anywhere in the W3 standards?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不会,因为这不是真的。在 box型号它说,这是用于保证金和margin-top and Margin and Margin -底部:
但是“无效”并不意味着这些属性不存在。具体而言,它们确实是出于继承目的而存在的。考虑此示例:
我们可以看到带有“两个”类的B元素继承了内联,非重取跨度元素的余量和底部属性,并且由于该B元素是inline-block,所以保证金顶和底部确实会导致布局差异。如果跨度不存在边缘顶部和底部属性,那将是不可能的。
You won't, because it isn't quite true. In the box model it says that for margin-top and margin-bottom:
But "no effect" does not mean that the properties don't exist. Specifically, they do exist for the purposes of inheritance. Consider this example:
We can see that the b element with class "two" inherits the margin top and bottom properties of the inline, non-replaced span element, and since that b element is inline-block, the margin-top and bottom do cause a layout difference. That would be impossible if the margin-top and bottom properties did not exist on the span.
在8.1 Box Model Spec中/tr/rec-css2/box.html#propdef-margin )“边缘边缘围绕着盒子边缘。如果边距具有0宽度(高度),则保证边缘与边框边缘相同。”
在页面中,您链接了10.6.1““高度”属性不适用,但框的高度由'Line-Height'属性给出。”因此,由于高度不适用,因此边缘边缘与边框边缘相同。
与上述相同的原因。 “盒子的高度由'线路高'属性给出。该强元素的高度是由
line-Height
设置的,因为它没有作为块或内线块元素的高度参考。我很确定您是否将其置于内联块属性,因为模型中的块具有高度。In 8.1 Box Model Spec (http://www.w3.org/TR/REC-CSS2/box.html#propdef-margin) "The margin edge surrounds the box margin. If the margin has 0 width(height), the margin edge is the same as the border edge."
In the page you linked 10.6.1 "The 'height' property doesn't apply, but the height of the box is given by the 'line-height' property." So since height doesn't apply, then the margin-edge is the same as the border edge.
Same reason as above. "the height of the box is given by the 'line-height' property". The height of that strong element is set by the
line-height
as it has no height to reference as a block or inline-block element would. I'm pretty sure if you gave it inline-block properties it would as a block has height in the model.尝试替换
保证金
padding
atstrong
element,添加display> display:inline-块
<代码>强样式Try substituting
margin
forpadding
atstrong
element, addingdisplay:inline-block
tostrong
style