position
属性的下一个选项是absolute
,它将元素相对于其父容器锁定到位。与relative
位置不同,这会从文档的正常流中移除元素,因此周围的项会忽略它。 CSS偏移属性(顶部或底部和左侧或右侧)用于调整位置。具有绝对定位的一个细微差别在于它将相对于其最近定位的祖先被锁定。如果您忘记向父项添加位置规则(通常使用position: relative;
),浏览器将继续查找链并最终默认为body标记。 position
声明为absolute
将#searchbar
元素锁定到其section
的右上角。给它每个50像素的top
和right
偏移。 #searchbar
元素的position
应设置为absolute
。'
testString: 'assert($("#searchbar").css("position") == "absolute", "The #searchbar
element should have a position
set to absolute
.");'
- text: '您的代码应该在#searchbar
元素上使用50像素的top
CSS偏移量。'
testString: 'assert($("#searchbar").css("top") == "50px", "Your code should use the top
CSS offset of 50 pixels on the #searchbar
element.");'
- text: '您的代码应该在#searchbar
元素上使用50像素的right
CSS偏移量。'
testString: 'assert($("#searchbar").css("right") == "50px", "Your code should use the right
CSS offset of 50 pixels on the #searchbar
element.");'
```