Update snippets

This commit is contained in:
Angelos Chalaris
2020-04-20 13:34:04 +03:00
parent d35dab24c3
commit 3077d4c71f
27 changed files with 141 additions and 386 deletions

View File

@ -6,7 +6,9 @@ tags: interactivity,intermediate
Reveals an interactive popout menu on hover and focus.
```html
<div class="reference" tabindex="0"><div class="popout-menu">Popout menu</div></div>
<div class="reference" tabindex="0">
<div class="popout-menu">Popout menu</div>
</div>
```
```css
@ -14,7 +16,7 @@ Reveals an interactive popout menu on hover and focus.
position: relative;
background: tomato;
width: 100px;
height: 100px;
height: 80px;
}
.popout-menu {
@ -23,7 +25,7 @@ Reveals an interactive popout menu on hover and focus.
left: 100%;
background: #333;
color: white;
padding: 15px;
padding: 16px;
}
.reference:hover > .popout-menu,
@ -35,12 +37,12 @@ Reveals an interactive popout menu on hover and focus.
#### Explanation
1. `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
2. `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
3. `left: 100%` moves the the popout menu 100% of its parent's width from the left.
4. `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).
5. `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
6. `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
7. `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.
- `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
- `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
- `left: 100%` moves the the popout menu 100% of its parent's width from the left.
- `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).
- `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
- `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
- `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.
#### Browser support