Skip to content

Commit 4b24c75

Browse files
committed
Extend box alignment helper classes to cover more use cases with Grid and flex helper
1 parent e0bfba6 commit 4b24c75

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

src/docs/css-helpers/box-alignment.mdx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ elsewhere.
1818
👉 If you need to quickly create a flex container, there is the
1919
[`.d-flex`](/css-helpers/display) helper class at your disposal.
2020

21-
📖 Read more about
22-
[flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox)
23-
and [grid](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids)
24-
layout concepts.
21+
📖 Read more about [flexbox] and [grid] layout concepts.
2522

2623
## Naming System
2724

@@ -32,31 +29,42 @@ The classes are named using the format `[alignment]-[value]` for `xs` and
3229
Where `alignment` is one of:
3330

3431
- `align-items`
32+
- `align-self`
3533
- `justify-content`
34+
- `justify-self`
3635

37-
For `align-items` the value can be:
36+
For `align-items` and `align-self` the value can be:
3837

38+
- `center`
3939
- `start`
4040
- `flex-start`
41-
- `center`
42-
- `baseline`
4341
- `end`
4442
- `flex-end`
43+
- `baseline`
44+
- `stretch`
4545

4646
For `justify-content` the value can be:
4747

48+
- `center`
4849
- `start`
4950
- `flex-start`
50-
- `center`
5151
- `end`
5252
- `flex-end`
5353
- `space-between`
5454

55+
For `justify-self` the value can be:
56+
57+
- `center`
58+
- `start`
59+
- `end`
60+
- `baseline`
61+
- `stretch`
62+
5563
👉 The difference between `start`/`flex-start` and `end`/`flex-end` is that the
5664
prefixed variants are intended for flexbox while the versions without prefix
57-
only work inside a grid layout.
65+
only work inside grid layout.
5866

59-
📖 [Read more about CSS Box Alignment concepts.](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Alignment)
67+
📖 [Read more about CSS Box Alignment concepts.][box-alignment]
6068

6169
## Horizontal (Main-Axis) Alignment (Justification)
6270

@@ -93,8 +101,8 @@ flexbox), `center`, `end` (`flex-end` for flexbox), and `space-between`.
93101

94102
## Vertical (Cross-Axis) Alignment
95103

96-
There are 6 options of alignment on the cross axis: `start` (`flex-start` for
97-
flexbox), `center`, `end` (`flex-end` for flexbox), and `baseline`.
104+
There are 7 options of alignment on the cross axis: `start` (`flex-start` for
105+
flexbox), `center`, `end` (`flex-end` for flexbox), `baseline`, and `stretch`.
98106

99107
<Playground>
100108
<>
@@ -129,6 +137,13 @@ flexbox), `center`, `end` (`flex-end` for flexbox), and `baseline`.
129137
</Placeholder>
130138
</div>
131139
</Placeholder>
140+
<Placeholder bordered>
141+
<div className="d-flex align-items-stretch" style={{ height: '6rem' }}>
142+
<Placeholder bordered>
143+
<code>.align-items-stretch</code>
144+
</Placeholder>
145+
</div>
146+
</Placeholder>
132147
</>
133148
</Playground>
134149

@@ -164,3 +179,7 @@ From `sm` up you can set the desired box alignment for individual
164179
</div>
165180
</>
166181
</Playground>
182+
183+
[flexbox]: https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox
184+
[grid]: https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids
185+
[box-alignment]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Alignment

src/lib/styles/settings/_utilities.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ $map: (
1414
responsive: true,
1515
property: align-items,
1616
class: align-items,
17-
values: (baseline, center, flex-start, flex-end),
17+
values: (center, start, flex-start, end, flex-end, baseline, stretch),
18+
),
19+
"align-self": (
20+
responsive: true,
21+
property: align-self,
22+
class: align-self,
23+
values: (center, start, flex-start, end, flex-end, baseline, stretch),
1824
),
1925
"justify-content": (
2026
responsive: true,
2127
property: justify-content,
2228
class: justify-content,
23-
values: (start, flex-start, end, flex-end, center, space-between),
29+
values: (center, start, flex-start, end, flex-end, space-between),
30+
),
31+
"justify-self": (
32+
responsive: true,
33+
property: justify-self,
34+
class: justify-self,
35+
values: (center, start, end, baseline, stretch),
2436
),
2537
"margin-top": (
2638
responsive: true,

0 commit comments

Comments
 (0)