Added solution to Lock an Element to its Parent with Absolute Positioning (#34317)
* Update index.md * Update index.md
This commit is contained in:
committed by
Randell Dawson
parent
2d07699cd6
commit
076c604f59
@ -1,10 +1,54 @@
|
||||
---
|
||||
title: Lock an Element to its Parent with Absolute Positioning
|
||||
---
|
||||
|
||||
 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
|
||||
|
||||
## Lock an Element to its Parent with Absolute Positioning
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/responsive-web-design/applied-visual-design/lock-an-element-to-its-parent-with-absolute-positioning/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
##  Hint: 1
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
Use `position: absolute;`.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
> _try to solve the problem now_
|
||||
|
||||
##  Hint: 2
|
||||
|
||||
Use the `right` and `top` properties.
|
||||
|
||||
> _try to solve the problem now_
|
||||
|
||||
## Spoiler Alert!
|
||||
|
||||

|
||||
|
||||
**Solution ahead!**
|
||||
|
||||
```html
|
||||
<style>
|
||||
#searchbar {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
right: 50px;
|
||||
}
|
||||
section {
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<h1>Welcome!</h1>
|
||||
<section>
|
||||
<form id="searchbar">
|
||||
<label for="search">Search:</label>
|
||||
<input type="search" id="search" name="search">
|
||||
<input type="submit" name="submit" value="Go!">
|
||||
</form>
|
||||
</section>
|
||||
</body>
|
||||
```
|
||||
|
||||
### Code Explanation:
|
||||
|
||||
* `#searchbar{}` selects all the elements with the ID of `searchbar`.
|
||||
* `position: absolute;` positions the element with respect to its nearest ancestor having `position: relative;`.
|
||||
* `top: 50px;` and `right: 50px;` offsets the element by `50px` to the bottom and left respectively.
|
||||
|
Reference in New Issue
Block a user