2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Move a Relatively Positioned Element with CSS Offsets
|
|
|
|
---
|
2019-03-09 19:35:30 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
# Move a Relatively Positioned Element with CSS Offsets
|
2019-03-09 19:35:30 +05:30
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2019-03-09 19:35:30 +05:30
|
|
|
|
|
|
|
Use the `left` property for offsetting the element right.
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2019-03-09 19:35:30 +05:30
|
|
|
|
|
|
|
Use the `bottom` property for offsetting the element top.
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
2019-03-09 19:35:30 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2019-03-09 19:35:30 +05:30
|
|
|
|
|
|
|
```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>
|
|
|
|
```
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
#### Code Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-03-09 19:35:30 +05:30
|
|
|
* The `h2{}` selects the `h2` element.
|
|
|
|
* `left: 15px;` offsets the `h2` `15px` to the right.
|
|
|
|
* `bottom: 10px;` offsets the `h2` `10px` to the top.
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|