--- id: 587d781e367417b2b2512acb title: Lock an Element to its Parent with Absolute Positioning challengeType: 0 videoUrl: '' localeTitle: 使用绝对定位将元素锁定到其父级 --- ## Description
CSS position属性的下一个选项是absolute ,它将元素相对于其父容器锁定到位。与relative位置不同,这会从文档的正常流中移除元素,因此周围的项会忽略它。 CSS偏移属性(顶部或底部和左侧或右侧)用于调整位置。具有绝对定位的一个细微差别在于它将相对于其最近定位的祖先被锁定。如果您忘记向父项添加位置规则(通常使用position: relative; ),浏览器将继续查找链并最终默认为body标记。
## Instructions
通过将其position声明为absolute#searchbar元素锁定到其section的右上角。给它每个50像素的topright偏移。
## Tests
```yml tests: - text: '#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.");' ```
## Challenge Seed
```html

Welcome!

```
## Solution
```js // solution required ```