Skip to content

Commit eba17d2

Browse files
authored
Merge pull request #966 from primer/flex-utilities
Rename `.flex-item-equal` to `.flex-1`
2 parents 0cde1c4 + 12aee98 commit eba17d2

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

docs/content/utilities/flexbox.md

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -487,44 +487,74 @@ When the main axis wraps, this creates multiple main axis lines and adds extra s
487487
Use this class to specify the ability of a flex item to alter its dimensions to fill available space.
488488

489489
```css
490-
.flex-auto { flex: 1 1 auto; }
491-
.flex-grow-0 { flex-grow: 0; }
492-
.flex-shrink-0 { flex-shrink: 0; }
490+
.flex-1 { flex: 1; }
491+
.flex-auto { flex: auto; }
492+
.flex-grow-0 { flex-grow: 0; }
493+
.flex-shrink-0 { flex-shrink: 0; }
493494
```
494495

495496
| Class | Description |
496497
| --- | --- |
497-
| `.flex-auto` | Sets default values for `flex-grow` (1), `flex-shrink` (1) and `flex-basis` (auto) |
498-
| `.flex-grow-0` | Prevents growing of a flex item |
499-
| `.flex-shrink-0` | Prevents shrinking of a flex item |
498+
| `.flex-1` | Fills available space |
499+
| `.flex-auto` | Fills available space and auto-sizes based on the content |
500+
| `.flex-grow-0` | Prevents growing of a flex item |
501+
| `.flex-shrink-0` | Prevents shrinking of a flex item |
502+
503+
#### flex-1
504+
505+
Adding `.flex-1` makes the item grow in size to take up all the space that is available.
506+
507+
```html live
508+
<div class="border d-flex">
509+
<div class="p-5 border bg-gray-light">flex item</div>
510+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
511+
<div class="p-5 border bg-gray-light">flex item</div>
512+
</div>
513+
```
514+
515+
Adding `.flex-1` to all flex items results in each item having the same size.
516+
517+
```html live
518+
<div class="border d-flex">
519+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
520+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
521+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
522+
</div>
523+
```
500524

501525
#### flex-auto
502526

527+
Using `.flex-auto` fills the available space but also takes the size of the content into account. Type in the editor below to see the effect.
528+
503529
```html live
504530
<div class="border d-flex">
505-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
506-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
507-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
531+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
532+
<div class="p-5 border bg-gray-light flex-auto">.flex-auto with a bit more text</div>
533+
<div class="p-5 border bg-gray-light flex-1">.flex-1</div>
508534
</div>
509535
```
510536

511537
#### flex-grow-0
512538

539+
Add `.flex-grow-0` to prevent an item from growing. This can be useful when used as a responsive variant. For example to stop growing when the viewport gets wider.
540+
513541
```html live
514542
<div class="border d-flex">
515-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
516-
<div class="p-5 border bg-gray-light flex-auto flex-grow-0">.flex-auto .flex-grow-0</div>
517-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
543+
<div class="p-5 border bg-gray-light">flex item</div>
544+
<div class="p-5 border bg-gray-light flex-auto flex-md-grow-0">.flex-auto .flex-md-grow-0</div>
545+
<div class="p-5 border bg-gray-light">flex item</div>
518546
</div>
519547
```
520548

521549
#### flex-shrink-0
522550

551+
Add `.flex-shrink-0` to prevent an item from shrinking. Note that for example text will not wrap and the flex items start to overflow if there is not enough space.
552+
523553
```html live
524-
<div class="border d-flex" style="width: 450px">
525-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
526-
<div class="p-5 border bg-gray-light flex-auto flex-shrink-0">.flex-auto .flex-shrink-0</div>
527-
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
554+
<div class="p-2 border d-flex" style="max-width: 340px">
555+
<div class="p-5 border bg-gray-light">flex item</div>
556+
<div class="p-5 border bg-gray-light flex-shrink-0">.flex-shrink-0</div>
557+
<div class="p-5 border bg-gray-light">flex item</div>
528558
</div>
529559
```
530560

@@ -663,7 +693,6 @@ All flexbox utilities can be adjusted per [breakpoint](/css/objects/grid#breakpo
663693

664694
- `d-[breakpoint]-[property]` for `display`
665695
- `flex-[breakpoint]-[property]-[behavior]` for various flex properties
666-
- `flex-[breakpoint]-item-equal` for equal width and equal height flex items
667696

668697
Each responsive style is applied to the specified breakpoint and up.
669698

@@ -682,8 +711,6 @@ Each responsive style is applied to the specified breakpoint and up.
682711
.flex-lg-nowrap {}
683712

684713
.flex-lg-self-start {}
685-
686-
.flex-md-item-equal {}
687714
```
688715

689716
#### Example usage
@@ -698,16 +725,6 @@ Mixing flex properties:
698725
</div>
699726
```
700727

701-
Using the equal width, equal height utilities:
702-
703-
```html live
704-
<div class="border d-flex">
705-
<div class="flex-md-item-equal p-3 border bg-gray-light">Stuff and things</div>
706-
<div class="flex-md-item-equal p-3 border bg-gray-light">More stuff<br> on multiple lines</div>
707-
<div class="flex-md-item-equal p-3 border bg-gray-light">Hi mom</div>
708-
</div>
709-
```
710-
711728
## Example components
712729

713730
The flex utilities can be used to create a number of components. Here are some examples.

src/utilities/flexbox.scss

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
.flex#{$variant}-content-stretch { align-content: stretch !important; }
3333

3434
// Item
35-
.flex#{$variant}-auto { flex: 1 1 auto !important; }
36-
.flex#{$variant}-grow-0 { flex-grow: 0 !important; }
35+
.flex#{$variant}-1 { flex: 1 !important; }
36+
.flex#{$variant}-auto { flex: auto !important; }
37+
.flex#{$variant}-grow-0 { flex-grow: 0 !important; }
3738
.flex#{$variant}-shrink-0 { flex-shrink: 0 !important; }
3839

3940
.flex#{$variant}-self-auto { align-self: auto !important; }
@@ -43,12 +44,6 @@
4344
.flex#{$variant}-self-baseline { align-self: baseline !important; }
4445
.flex#{$variant}-self-stretch { align-self: stretch !important; }
4546

46-
// Shorthand for equal width and height cols
47-
.flex#{$variant}-item-equal {
48-
flex-grow: 1;
49-
flex-basis: 0;
50-
}
51-
5247
.flex#{$variant}-order-1 { order: 1 !important; }
5348
.flex#{$variant}-order-2 { order: 2 !important; }
5449
.flex#{$variant}-order-none { order: inherit !important; }

0 commit comments

Comments
 (0)