mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-29 16:49:58 +02:00
feat: Circular navigation
This commit is contained in:
7
contents/_includes/covers/circular-navigation.njk
Normal file
7
contents/_includes/covers/circular-navigation.njk
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="circular-navigation">
|
||||
{% for i in range(0, 6) -%}
|
||||
<div class="circular-navigation__circle circular-navigation__circle--{{ i + 1 }}">
|
||||
<div class="circular-navigation__content">{{ i + 1 }}</div>
|
||||
</div>
|
||||
{%- endfor %}
|
||||
</div>
|
73
contents/circular-navigation.md
Normal file
73
contents/circular-navigation.md
Normal file
@@ -0,0 +1,73 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Circular navigation
|
||||
description: Create a circular navigation with CSS flexbox
|
||||
keywords: css circular navigation, css flexbox
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="circular-navigation">
|
||||
<!-- The trigger element that will show all circles when user clicks it -->
|
||||
...
|
||||
|
||||
<!-- A circle menu item -->
|
||||
<div class="circular-navigation__circle">
|
||||
<!-- The content -->
|
||||
<div class="circular-navigation__content">
|
||||
...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Repeat menu items -->
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.circular-navigation {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.circular-navigation__circle {
|
||||
/* Position */
|
||||
position: absolute;
|
||||
top: 0;
|
||||
|
||||
/*
|
||||
3rem is the distance from the item to the trigger element.
|
||||
Replace 0deg with 60deg, 180deg, 240deg, 300deg for another item
|
||||
in case you want to have a total of 6 menu items.
|
||||
The formulation is 360 / numberOfItems * indexOfItem
|
||||
*/
|
||||
transform: rotate(0deg) translateX(-3rem);
|
||||
|
||||
/* Must have the same size as the trigger element */
|
||||
height: 2rem;
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.circular-navigation__content {
|
||||
/*
|
||||
Rotate it to make it displayed vertically
|
||||
Replace -0deg with -60deg, -180deg, -240deg, -300deg for another item
|
||||
in case you want to have a total of 6 menu items.
|
||||
The formulation is -(360 / numberOfItems * indexOfItem)
|
||||
*/
|
||||
transform: rotate(-0deg);
|
||||
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
/* Take full size */
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}{% include "covers/circular-navigation.njk" %}{% enddemo %}
|
@@ -126,6 +126,7 @@ eleventyExcludeFromCollections: true
|
||||
<h2 class="category__name">Navigation</h2>
|
||||
<div class="category__posts">
|
||||
{% pattern "Breadcrumb" %}{% include "covers/breadcrumb.njk" %}{% endpattern %}
|
||||
{% pattern "Circular navigation" %}{% include "covers/circular-navigation.njk" %}{% endpattern %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user