Skip to content

Commit d136c10

Browse files
authored
Merge pull request #763 from primer/flex_utilities
Adding flex utilities for grow, order, and width
2 parents 4f167fa + 1f8274f commit d136c10

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

pages/css/utilities/flexbox.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,17 @@ When the main axis wraps, this creates multiple main axis lines and adds extra s
472472

473473
Use this class to specify the ability of a flex item to alter its dimensions to fill available space.
474474

475-
```CSS
476-
.flex-auto { flex: 1 1 auto; }
475+
```css
476+
.flex-auto { flex: 1 1 auto; }
477+
.flex-grow-0 { flex-grow: 0; }
478+
.flex-shrink-0 { flex-shrink: 0; }
477479
```
478480

479481
| Class | Description |
480482
| --- | --- |
481483
| `.flex-auto` | Sets default values for `flex-grow` (1), `flex-shrink` (1) and `flex-basis` (auto) |
484+
| `.flex-grow-0` | Prevents growing of a flex item |
485+
| `.flex-shrink-0` | Prevents shrinking of a flex item |
482486

483487
#### flex-auto
484488

@@ -490,6 +494,26 @@ Use this class to specify the ability of a flex item to alter its dimensions to
490494
</div>
491495
```
492496

497+
#### flex-grow-0
498+
499+
```html
500+
<div class="border d-flex">
501+
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
502+
<div class="p-5 border bg-gray-light flex-auto flex-grow-0">.flex-auto .flex-grow-0</div>
503+
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
504+
</div>
505+
```
506+
507+
#### flex-shrink-0
508+
509+
```html
510+
<div class="border d-flex" style="width: 450px">
511+
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
512+
<div class="p-5 border bg-gray-light flex-auto flex-shrink-0">.flex-auto .flex-shrink-0</div>
513+
<div class="p-5 border bg-gray-light flex-auto">.flex-auto</div>
514+
</div>
515+
```
516+
493517
## Align self
494518

495519
Use these classes to adjust the alignment of an individual flex item on the cross axis. This overrides any `align-items` property applied to the flex container.
@@ -576,6 +600,49 @@ Use these classes to adjust the alignment of an individual flex item on the cros
576600
</div>
577601
```
578602

603+
## Order
604+
605+
Use these classes to change the order of flex items. Keep in mind that it won't affect screen readers or navigating with the keyboard and it's advised to keep the markup in a logical source order.
606+
607+
#### CSS
608+
609+
```css
610+
.flex-order-1 { order: 1; }
611+
.flex-order-2 { order: 2; }
612+
.flex-order-none { order: inherit; }
613+
614+
```
615+
616+
#### Classes
617+
618+
| Class | Description |
619+
| --- | --- |
620+
| `.flex-order-1` | Set order to be 1 |
621+
| `.flex-order-2` | Set order to be 2 |
622+
| `.flex-order-none` | Remove order (typically used with responsive variants) |
623+
624+
#### flex-order (1+2)
625+
626+
```html
627+
<div class="border d-flex">
628+
<div class="p-5 border bg-gray-light flex-order-2">1. .flex-order-2</div>
629+
<div class="p-5 border bg-gray-light">2.</div>
630+
<div class="p-5 border bg-gray-light flex-order-1">3. .flex-order-1</div>
631+
</div>
632+
```
633+
634+
#### flex-order-none
635+
636+
Resize window to see the effect.
637+
638+
```html
639+
<div class="border d-flex">
640+
<div class="p-5 border bg-gray-light flex-order-1 flex-md-order-none">1. .flex-order-1 .flex-md-order-none</div>
641+
<div class="p-5 border bg-gray-light">2.</div>
642+
<div class="p-5 border bg-gray-light">3.</div>
643+
</div>
644+
```
645+
579646
## Responsive flex utilities
580647

581648
All flexbox utilities can be adjusted per [breakpoint](/css/objects/grid#breakpoints) using the following formulas:

pages/css/utilities/layout.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ Use `.width-full` to set width to 100%.
190190
</div>
191191
```
192192

193+
Use `.width-auto` to reset width to `auto` (initial value). Typically used with **responsive variants**. Resize the window to see the effect in the example below.
194+
195+
```html
196+
<div class="d-table width-full width-md-auto">
197+
<div class="d-table-cell">
198+
<input class="form-control width-full" type="text" value="Responsive width form field" aria-label="Sample full responsive width form field">
199+
</div>
200+
</div>
201+
```
202+
193203
Use `.height-fit` to set max-height 100%.
194204

195205
```html

src/utilities/flexbox.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
// Item
3636
.flex#{$variant}-auto { flex: 1 1 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; }
@@ -48,5 +49,9 @@
4849
flex-grow: 1;
4950
flex-basis: 0;
5051
}
52+
53+
.flex#{$variant}-order-1 { order: 1 !important; }
54+
.flex#{$variant}-order-2 { order: 2 !important; }
55+
.flex#{$variant}-order-none { order: inherit !important; }
5156
}
5257
}

src/utilities/layout.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676

7777
@each $breakpoint, $variant in $responsive-variants {
7878
@include breakpoint($breakpoint) {
79+
80+
// Auto varients
81+
.width#{$variant}-auto { width: auto !important; }
82+
7983
/* Set the direction to rtl */
8084
.direction#{$variant}-rtl { direction: rtl !important; }
8185
/* Set the direction to ltr */

0 commit comments

Comments
 (0)