50 lines
1.6 KiB
Markdown
50 lines
1.6 KiB
Markdown
---
|
|
title: Move a Relatively Positioned Element with CSS Offsets
|
|
---
|
|
|
|
 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
|
|
|
|
## Move a Relatively Positioned Element with CSS Offsets
|
|
|
|
##  Hint: 1
|
|
|
|
Use the `left` property for offsetting the element right.
|
|
|
|
> _try to solve the problem now_
|
|
|
|
##  Hint: 2
|
|
|
|
Use the `bottom` property for offsetting the element top.
|
|
|
|
> _try to solve the problem now_
|
|
|
|
## Spoiler Alert!
|
|
|
|

|
|
|
|
**Solution ahead!**
|
|
|
|
The following lines of code solves the challenge:
|
|
```html
|
|
<head>
|
|
<style>
|
|
h2 {
|
|
position: relative;
|
|
left: 15px;
|
|
bottom: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>On Being Well-Positioned</h1>
|
|
<h2>Move me!</h2>
|
|
<p>I still think the h2 is where it normally sits.</p>
|
|
</body>
|
|
```
|
|
|
|
### Code Explanation:
|
|
|
|
* The `h2{}` selects the `h2` element.
|
|
* `left: 15px;` offsets the `h2` `15px` to the right.
|
|
* `bottom: 10px;` offsets the `h2` `10px` to the top.
|