1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-03 20:58:02 +02:00
Files
csslayout/contents/wizard.mdx
2023-09-01 07:43:57 +07:00

215 lines
4.4 KiB
Plaintext

---
category: Navigation
created: '2019-11-22'
description: Create a wizard with CSS flexbox
keywords: css flexbox, css stepper, css wizard
thumbnail: /assets/css-layout/thumbnails/wizard.png
title: Wizard
---
## HTML
```html index.html
<div class="wizard">
<!-- Step -->
<div class="wizard__step">
<div class="wizard__dot">
<!-- The left connector -->
<div class="wizard__connector"></div>
<!-- The step number -->
<div class="wizard__number">...</div>
<!-- The right connector -->
<div class="wizard__connector"></div>
</div>
<!-- Title of step -->
...
</div>
<!-- Repeat other steps -->
...
</div>
```
## CSS
```css styles.css
.wizard {
display: flex;
}
.wizard__step {
/* Make all steps have the same width */
flex: 1;
}
.wizard__dot {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.wizard__connector {
flex: 1;
height: 1px;
background-color: #d1d5db;
}
.wizard__step:first-child .wizard__connector:first-child,
.wizard__step:last-child .wizard__connector:last-child {
background-color: transparent;
}
.wizard__number {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Rounded border */
background-color: #d1d5db;
border-radius: 9999px;
height: 2rem;
width: 2rem;
/* OPTIONAL: Spacing between it and connectors */
margin-left: 0.25rem;
margin-right: 0.25rem;
}
```
<Playground>
```css placeholders.css hidden
.lines {
padding: 0.25rem 0;
width: 100%;
align-items: center;
display: flex;
justify-content: center;
flex-direction: column;
}
.line {
background: #d1d5db;
height: 1px;
margin-bottom: 0.25rem;
}
.line.line--20 {
width: 20%;
}
.line.line--40 {
width: 40%;
}
.line.line--60 {
width: 60%;
}
.line.line--80 {
width: 80%;
}
.line.line--100 {
width: 100%;
}
```
```css styles.css hidden
body {
align-items: center;
display: flex;
justify-content: center;
}
.wizard {
align-items: center;
display: flex;
justify-content: center;
width: 16rem;
}
.wizard__step {
/* Make all steps have the same width */
flex: 1;
}
.wizard__dot {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
.wizard__connector {
flex: 1;
height: 1px;
background-color: #d1d5db;
}
.wizard__step:first-child .wizard__connector:first-child,
.wizard__step:last-child .wizard__connector:last-child {
background-color: transparent;
}
.wizard__number {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Rounded border */
background-color: #d1d5db;
border-radius: 9999px;
height: 1rem;
width: 1rem;
}
```
```html index.html hidden
<div class="wizard">
<div class="wizard__step">
<div class="wizard__dot">
<div class="wizard__connector"></div>
<div class="wizard__number"></div>
<div class="wizard__connector"></div>
</div>
<div class="lines">
<div class="line line--20"></div>
<div class="line line--40"></div>
<div class="line line--80"></div>
<div class="line line--60"></div>
<div class="line line--20"></div>
</div>
</div>
<div class="wizard__step">
<div class="wizard__dot">
<div class="wizard__connector"></div>
<div class="wizard__number"></div>
<div class="wizard__connector"></div>
</div>
<div class="lines">
<div class="line line--20"></div>
<div class="line line--40"></div>
<div class="line line--80"></div>
<div class="line line--60"></div>
<div class="line line--20"></div>
</div>
</div>
<div class="wizard__step">
<div class="wizard__dot">
<div class="wizard__connector"></div>
<div class="wizard__number"></div>
<div class="wizard__connector"></div>
</div>
<div class="lines">
<div class="line line--20"></div>
<div class="line line--40"></div>
<div class="line line--80"></div>
<div class="line line--60"></div>
<div class="line line--20"></div>
</div>
</div>
</div>
```
</Playground>