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

127 lines
2.1 KiB
Plaintext

---
category: Input
created: '2019-11-16'
description: Create a stepper input with CSS flexbox
keywords: css flexbox, css stepper input
thumbnail: /assets/css-layout/thumbnails/stepper-input.png
title: Stepper input
---
## HTML
```html index.html
<div class="stepper-input">
<!-- Minus button -->
<button class="stepper-input__button">-</button>
<!-- Input container -->
<div class="stepper-input__content">
<input type="text" class="stepper-input__input" />
</div>
<!-- Plus button -->
<button class="stepper-input__button">+</button>
</div>
```
## CSS
```css styles.css
.stepper-input {
display: flex;
/* Border */
border: 1px solid #d1d5db;
border-radius: 0.25rem;
/* Size */
height: 2rem;
}
.stepper-input__button {
/* Reset */
background: #d1d5db;
border: none;
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Size */
width: 2rem;
}
.stepper-input__content {
flex: 1;
}
.stepper-input__input {
/* Reset */
border: none;
/* Take full size of its container */
height: 100%;
width: 100%;
}
```
<Playground>
```css styles.css hidden
body {
align-items: center;
display: flex;
justify-content: center;
}
.stepper-input {
display: flex;
/* Border */
border: 1px solid #d1d5db;
border-radius: 0.25rem;
/* Size */
height: 2rem;
width: 16rem;
}
.stepper-input__button {
/* Reset */
background: #d1d5db;
border: none;
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Size */
width: 2rem;
}
.stepper-input__content {
flex: 1;
}
.stepper-input__input {
/* Reset */
border: none;
/* Take full size of its container */
height: 100%;
width: 100%;
}
```
```html index.html hidden
<div class="stepper-input">
<button class="stepper-input__button">-</button>
<div class="stepper-input__content">
<input type="text" class="stepper-input__input" />
</div>
<button class="stepper-input__button">+</button>
</div>
```
</Playground>