CSS Box Model
。块级项目自动从新行开始(想想标题,段落和div),而内联项目位于周围内容(如图像或跨度)中。以这种方式的元素的默认布局称为文档的normal flow
,但CSS提供position属性来覆盖它。当元素的位置设置为relative
,它允许您指定CSS应如何相对于页面正常流中的当前位置移动它。它与left
或right
以及top
或bottom
的CSS偏移属性配对。这些表示将物品从通常定位的位置移开的像素,百分比或ems的数量。以下示例将段落从底部移开10个像素: p {将元素的位置更改为相对位置不会将其从正常流中移除 - 其周围的其他元素仍然表现为该项位于其默认位置。 注意
位置:相对;
底部:10px;
}
h2
的position
更改为relative
position
,并使用CSS偏移将其移动到距离正常流动位置top
15个像素的位置。请注意,周围的h1和p元素的位置没有影响。 h2
元素的position
属性应设置为relative
。
testString: 'assert($("h2").css("position") == "relative", "The h2
element should have a position
property set to relative
.");'
- text: 您的代码应该使用CSS偏移来相对地将h2
15px定位在远离其正常位置的top
。
testString: 'assert($("h2").css("top") == "15px", "Your code should use a CSS offset to relatively position the h2
15px away from the top
of where it normally sits.");'
```
I still think the h2 is where it normally sits.
```