Skip to content

Commit ffaad0a

Browse files
authored
Responsive display utilities (#20934)
* Explore responsive display utils, but with a twist: lowest breakpoint has no breakpoint modifier in the class name * make floats use the same format, add float-none mixin
1 parent 76d5340 commit ffaad0a

File tree

12 files changed

+73
-50
lines changed

12 files changed

+73
-50
lines changed

docs/components/card.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Use Bootstrap's nav pills or tabs within a card header. Be sure to always includ
231231
{% example html %}
232232
<div class="card text-xs-center">
233233
<div class="card-header">
234-
<ul class="nav nav-tabs card-header-tabs float-xs-left">
234+
<ul class="nav nav-tabs card-header-tabs float-left">
235235
<li class="nav-item">
236236
<a class="nav-link active" href="#">Active</a>
237237
</li>
@@ -254,7 +254,7 @@ Use Bootstrap's nav pills or tabs within a card header. Be sure to always includ
254254
{% example html %}
255255
<div class="card text-xs-center">
256256
<div class="card-header">
257-
<ul class="nav nav-pills card-header-pills float-xs-left">
257+
<ul class="nav nav-pills card-header-pills float-left">
258258
<li class="nav-item">
259259
<a class="nav-link active" href="#">Active</a>
260260
</li>

docs/components/list-group.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ Add badges to any list group item to show unread counts, activity, etc.
3232
{% example html %}
3333
<ul class="list-group">
3434
<li class="list-group-item">
35-
<span class="badge badge-default badge-pill float-xs-right">14</span>
35+
<span class="badge badge-default badge-pill float-right">14</span>
3636
Cras justo odio
3737
</li>
3838
<li class="list-group-item">
39-
<span class="badge badge-default badge-pill float-xs-right">2</span>
39+
<span class="badge badge-default badge-pill float-right">2</span>
4040
Dapibus ac facilisis in
4141
</li>
4242
<li class="list-group-item">
43-
<span class="badge badge-default badge-pill float-xs-right">1</span>
43+
<span class="badge badge-default badge-pill float-right">1</span>
4444
Morbi leo risus
4545
</li>
4646
</ul>

docs/components/navbar.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Here's an example of all the sub-components included in a default, non-responsiv
5555
</div>
5656
</li>
5757
</ul>
58-
<form class="form-inline float-xs-right">
58+
<form class="form-inline float-right">
5959
<input class="form-control" type="text" placeholder="Search">
6060
<button class="btn btn-outline-success" type="submit">Search</button>
6161
</form>
@@ -171,7 +171,7 @@ Place various form controls and components within a navbar with `.form-inline`.
171171

172172
{% example html %}
173173
<nav class="navbar navbar-light bg-faded">
174-
<form class="form-inline float-xs-left">
174+
<form class="form-inline float-left">
175175
<input class="form-control" type="text" placeholder="Search">
176176
<button class="btn btn-outline-success" type="submit">Search</button>
177177
</form>
@@ -182,7 +182,7 @@ Input groups work, too:
182182

183183
{% example html %}
184184
<nav class="navbar navbar-light bg-faded">
185-
<form class="form-inline float-xs-left">
185+
<form class="form-inline float-left">
186186
<div class="input-group">
187187
<span class="input-group-addon" id="basic-addon1">@</span>
188188
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
@@ -195,7 +195,7 @@ Various buttons are supported as part of these navbar forms, too. This is also a
195195

196196
{% example html %}
197197
<nav class="navbar navbar-light bg-faded">
198-
<form class="form-inline float-xs-left">
198+
<form class="form-inline float-left">
199199
<button class="btn btn-outline-success" type="button">Main button</button>
200200
<button class="btn btn-sm align-middle btn-outline-secondary" type="button">Smaller button</button>
201201
</form>
@@ -218,7 +218,7 @@ Using our utility classes, you can change the alignment and appearance of your n
218218

219219
{% example html %}
220220
<nav class="navbar navbar-light bg-faded">
221-
<span class="navbar-text float-xs-right text-muted">
221+
<span class="navbar-text float-right text-muted">
222222
Muted navbar text that's floated right
223223
</span>
224224
</nav>
@@ -229,7 +229,7 @@ Similarly, you can use utility classes to align navbar text to other navbar elem
229229
{% example html %}
230230
<nav class="navbar navbar-light bg-faded">
231231
<a class="navbar-brand" href="#">Navbar</a>
232-
<span class="navbar-text float-xs-left">
232+
<span class="navbar-text float-left">
233233
Navbar text that's floated left
234234
</span>
235235
</nav>
@@ -258,7 +258,7 @@ Here are some examples to show what we mean.
258258
<a class="nav-link" href="#">About</a>
259259
</li>
260260
</ul>
261-
<form class="form-inline float-xs-right">
261+
<form class="form-inline float-right">
262262
<input class="form-control" type="text" placeholder="Search">
263263
<button class="btn btn-outline-info" type="submit">Search</button>
264264
</form>
@@ -279,7 +279,7 @@ Here are some examples to show what we mean.
279279
<a class="nav-link" href="#">About</a>
280280
</li>
281281
</ul>
282-
<form class="form-inline float-xs-right">
282+
<form class="form-inline float-right">
283283
<input class="form-control" type="text" placeholder="Search">
284284
<button class="btn btn-outline-secondary" type="submit">Search</button>
285285
</form>
@@ -300,7 +300,7 @@ Here are some examples to show what we mean.
300300
<a class="nav-link" href="#">About</a>
301301
</li>
302302
</ul>
303-
<form class="form-inline float-xs-right">
303+
<form class="form-inline float-right">
304304
<input class="form-control" type="text" placeholder="Search">
305305
<button class="btn btn-outline-primary" type="submit">Search</button>
306306
</form>

docs/content/images.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ In addition to our [border-radius utilities]({{ site.baseurl }}/utilities/border
4747
Align images with the [helper float classes]({{ site.baseurl }}/utilities/responsive-helpers/#responsive-floats) or [text alignment classes]({{ site.baseurl }}/utilities/typography/#text-alignment). `block`-level images can be centered using [the `.mx-auto` margin utility class]({{ site.baseurl }}/utilities/spacing/#horizontal-centering).
4848

4949
<div class="bd-example bd-example-images">
50-
<img data-src="holder.js/200x200" class="rounded float-xs-left" alt="A generic square placeholder image with rounded corners">
51-
<img data-src="holder.js/200x200" class="rounded float-xs-right" alt="A generic square placeholder image with rounded corners">
50+
<img data-src="holder.js/200x200" class="rounded float-left" alt="A generic square placeholder image with rounded corners">
51+
<img data-src="holder.js/200x200" class="rounded float-right" alt="A generic square placeholder image with rounded corners">
5252
</div>
5353

5454
{% highlight html %}
55-
<img src="..." class="rounded float-xs-left" alt="...">
56-
<img src="..." class="rounded float-xs-right" alt="...">
55+
<img src="..." class="rounded float-left" alt="...">
56+
<img src="..." class="rounded float-right" alt="...">
5757
{% endhighlight %}
5858

5959
<div class="bd-example bd-example-images">

docs/migration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ Dropped entirely for the new card component.
185185

186186
### Utilities
187187

188-
- Added `.float-{xs,sm,md,lg,xl}-{left,right,none}` classes for responsive floats and removed `.pull-left` and `.pull-right` since they're redundant to `.float-xs-left` and `.float-xs-right`.
188+
- Made display utilities responsive (e.g., `.d-none` and `d-{sm,md,lg,xl}-none`).
189+
- Added `.float-{sm,md,lg,xl}-{left,right,none}` classes for responsive floats and removed `.pull-left` and `.pull-right` since they're redundant to `.float-left` and `.float-right`.
189190
- Added responsive variations to our text alignment classes `.text-{xs,sm,md,lg,xl}-{left,center,right}` and removed the redundant `.text-{left,center,right}` utilities as they are the same as the `xs` variation.
190191
- Dropped `.center-block` for the new `.mx-auto` class.
191192

docs/utilities/clearfix.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The following example shows how the clearfix can be used. Without the clearfix t
3333

3434
{% example html %}
3535
<div class="bg-info clearfix">
36-
<button class="btn btn-secondary float-xs-left">Example Button pulled left</button>
37-
<button class="btn btn-secondary float-xs-right">Example Button pullred right</button>
36+
<button class="btn btn-secondary float-left">Example Button pulled left</button>
37+
<button class="btn btn-secondary float-right">Example Button pullred right</button>
3838
</div>
3939
{% endexample %}

docs/utilities/responsive-helpers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ These utility classes float an element to the left or right, or disable floating
4949
Two similar non-responsive Sass mixins (`float-left` and `float-right`) are also available.
5050

5151
{% example html %}
52-
<div class="float-xs-left">Float left on all viewport sizes</div><br>
53-
<div class="float-xs-right">Float right on all viewport sizes</div><br>
54-
<div class="float-xs-none">Don't float on all viewport sizes</div><br>
52+
<div class="float-left">Float left on all viewport sizes</div><br>
53+
<div class="float-right">Float right on all viewport sizes</div><br>
54+
<div class="float-none">Don't float on all viewport sizes</div><br>
5555

5656
<div class="float-sm-left">Float left on viewports sized SM (small) or wider</div><br>
5757
<div class="float-md-left">Float left on viewports sized MD (medium) or wider</div><br>

js/dist/alert.js

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/alert.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scss/mixins/_float.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
@mixin float-right {
55
float: right !important;
66
}
7+
@mixin float-none {
8+
float: none !important;
9+
}

scss/utilities/_display.scss

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,29 @@
22
// Display utilities
33
//
44

5-
.d-block {
6-
display: block !important;
7-
}
8-
.d-inline-block {
9-
display: inline-block !important;
10-
}
11-
.d-inline {
12-
display: inline !important;
5+
6+
@each $breakpoint in map-keys($grid-breakpoints) {
7+
@include media-breakpoint-up($breakpoint) {
8+
$min: breakpoint-min($breakpoint, $grid-breakpoints);
9+
10+
@if $min {
11+
@media (min-width: $min) {
12+
.d-#{$breakpoint}-none { display: none !important; }
13+
.d-#{$breakpoint}-inline { display: inline !important; }
14+
.d-#{$breakpoint}-inline-block { display: inline-block !important; }
15+
.d-#{$breakpoint}-block { display: block !important; }
16+
.d-#{$breakpoint}-table { display: table !important; }
17+
.d-#{$breakpoint}-table-cell { display: table-cell !important; }
18+
.d-#{$breakpoint}-flex { display: flex !important; }
19+
}
20+
} @else {
21+
.d-none { display: none !important; }
22+
.d-inline { display: inline !important; }
23+
.d-inline-block { display: inline-block !important; }
24+
.d-block { display: block !important; }
25+
.d-table { display: table !important; }
26+
.d-table-cell { display: table-cell !important; }
27+
.d-flex { display: flex !important; }
28+
}
29+
}
1330
}

scss/utilities/_float.scss

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
@each $breakpoint in map-keys($grid-breakpoints) {
22
@include media-breakpoint-up($breakpoint) {
3-
.float-#{$breakpoint}-left {
4-
@include float-left();
5-
}
6-
.float-#{$breakpoint}-right {
7-
@include float-right();
8-
}
9-
.float-#{$breakpoint}-none {
10-
float: none !important;
3+
$min: breakpoint-min($breakpoint, $grid-breakpoints);
4+
5+
@if $min {
6+
// everything else
7+
@media (min-width: $min) {
8+
.float-#{$breakpoint}-left { @include float-left; }
9+
.float-#{$breakpoint}-right { @include float-right; }
10+
.float-#{$breakpoint}-none { @include float-none; }
11+
}
12+
} @else {
13+
// xs
14+
.float-left { @include float-left; }
15+
.float-right { @include float-right; }
16+
.float-none { @include float-none; }
1117
}
1218
}
1319
}

0 commit comments

Comments
 (0)