首页 > CSS padding-top的问题。

CSS padding-top的问题。

给了b上下左右内边距,可在网页上查看为什么上边距没了。


楼主把所有的代码贴出来啊,就截张图看不出来你错哪的。


楼主试试这样看....

应该是行内元素造成的,你把b元素的display 设置成 block 或者inline-block试试


我按照你提供的代码试了一下
若设置为行内元素,则与你的效果一样。(其中父级元素body为margin:0)
若父级元素body有设置margin:8px,则是下图的效果。

若设置为inline-block或者block,则效果是这样的。

You can add padding to the top and bottom of inline element, but the padding doesn’t affect the spacing of the other inline elements around it, so the padding will overlap other inline elements

也就是说对于行内元素而言,垂直方向的padding是会叠加的,但水平方向的padding不会叠加。如下图所示


对于行内非替换元素来说,padding/margin属性对其行内框的形成没有作用,也就是是说无论padding设置的有多大,在垂直方向上不会影响其实际形成的行框的高度,在水平方向上会影响其和相邻元素的左右距离。

你的效果之所以文本紧贴在可视区域的顶部,是因为你把body的margin设置为0了

【热门文章】
【热门文章】