mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-31 17:41:42 +02:00
feat: Radio button group
This commit is contained in:
14
contents/_includes/patterns/radio-button-group.njk
Normal file
14
contents/_includes/patterns/radio-button-group.njk
Normal file
@@ -0,0 +1,14 @@
|
||||
<div class="radio-button-group">
|
||||
<label class="radio-button-group__label">
|
||||
<input type="radio" class="radio-button-group__input" /> S
|
||||
</label>
|
||||
<label class="radio-button-group__label radio-button-group__label--selected">
|
||||
<input type="radio" class="radio-button-group__input" /> M
|
||||
</label>
|
||||
<label class="radio-button-group__label">
|
||||
<input type="radio" class="radio-button-group__input" /> L
|
||||
</label>
|
||||
<label class="radio-button-group__label">
|
||||
<input type="radio" class="radio-button-group__input" /> XL
|
||||
</label>
|
||||
</div>
|
@@ -93,6 +93,7 @@ eleventyExcludeFromCollections: true
|
||||
{% pattern "Custom radio button" %}{% include "patterns/custom-radio-button.njk" %}{% endpattern %}
|
||||
{% pattern "Floating label" %}{% include "patterns/floating-label.njk" %}{% endpattern %}
|
||||
{% pattern "Input addon" %}{% include "patterns/input-addon.njk" %}{% endpattern %}
|
||||
{% pattern "Radio button group" %}{% include "patterns/radio-button-group.njk" %}{% endpattern %}
|
||||
{% pattern "Radio switch" %}{% include "patterns/radio-switch.njk" %}{% endpattern %}
|
||||
{% pattern "Rating" %}{% include "patterns/rating.njk" %}{% endpattern %}
|
||||
{% pattern "Search box" %}{% include "patterns/search-box.njk" %}{% endpattern %}
|
||||
|
76
contents/radio-button-group.md
Normal file
76
contents/radio-button-group.md
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Radio button group
|
||||
description: Create a radio button group with CSS flexbox
|
||||
keywords: css flexbox, css radio button
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="radio-button-group">
|
||||
<!-- Each radio item -->
|
||||
<label class="radio-button-group__label">
|
||||
<!-- The radio input -->
|
||||
<input type="radio" class="radio-button-group__input" />
|
||||
|
||||
<!-- The text -->
|
||||
...
|
||||
</label>
|
||||
|
||||
<!-- Selected item -->
|
||||
<label class="radio-button-group__label radio-button-group__label--selected">
|
||||
...
|
||||
</label>
|
||||
|
||||
<!-- Repeat other items -->
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.radio-button-group {
|
||||
display: flex;
|
||||
|
||||
/* Border */
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.radio-button-group__label {
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
|
||||
border-right: 1px solid #d1d5db;
|
||||
padding: 0.5rem;
|
||||
|
||||
/* For not selected radio */
|
||||
background-color: transparent;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.radio-button-group__label:last-child {
|
||||
/* Remove the right border from the last label */
|
||||
border-right-color: transparent;
|
||||
}
|
||||
|
||||
.radio-button-group__label--selected {
|
||||
/* For selected radio */
|
||||
background-color: #3b82f6;
|
||||
color: #fff;
|
||||
|
||||
margin-top: -1px;
|
||||
margin-bottom: -1px;
|
||||
}
|
||||
|
||||
.radio-button-group__input {
|
||||
/* Hide it */
|
||||
display: none;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}{% include "patterns/radio-button-group.njk" %}{% enddemo %}
|
Reference in New Issue
Block a user