- Mastering Bootstrap 4(Second Edition)
- Benjamin Jakobus Jason Marah
- 388字
- 2021-06-24 19:25:54
Responsive utilities
Responsive utilities are a group of media query-based classes that control when an element should be hidden or shown depending on the viewport. One popular use case for this is controlling display-specific navigation. For example, a page may have a navigation bar on large displays and a hidden navigation on small displays, which is only displayed when a user chooses to open the navigation.
Let's look at a quick example with our Print Size page. Add the d-none and d-sm-block classes to the img elements:
<div class="container">
<h1>Our Print Sizes</h1>
<div class="row">
<div class="col-sm-3">
<img src="images/small.jpg" class="img-fluid rounded-circle
d-none d-sm-block">
<h5>Small</h5>
...
</div>
<div class="col-sm-3">
<img src="images/medium.jpg" class="img-fluid rounded d-
none d-sm-block">
<h5>Medium</h5>
...
</div>
<div class="col-sm-3">
<img src="images/large.jpg" class="img-thumbnail d-none d-
sm-block">
<h5>Large</h5>
...
</div>
<div class="col-sm-3">
<img src="images/extra-large.jpg" class="img-fluid d-none
d-sm-block">
<h5>Extra Large</h5>
...
</div>
</div>
</div>
The d-done class, as its name implies, sets the display property of the element to which it is applied to none. This makes the element invisible across the board, regardless of the viewport width. On the other hand, the d-sm-block class sets the display property of the element block, making it visible. The combination of these two classes ensures that the element in question becomes visible for small displays and above. This is the equivalent of using the hidden-xs class in Bootstrap 3:

It should be noted that, once again, Bootstrap offers different variations of these classes, depending on the required breakpoint and property value. For example, d-sm-none, d-md-block, d-sm-block-inline, d-md-inline, and so on.
Bootstrap 3 only offers hidden-* (where * refers to the viewport size. For example, hidden-xs). As such, to hide an element only when the display is extra-small, we will add the hidden-xs class to our element when using Bootstrap 3. The hidden-* classes have been dropped from Bootstrap 4.
That is, the d-* classes stick to the conventions found in the grid system. In the grid system, col-md targets all Medium displays and below. Likewise, d-md—none will target only Medium displays or displays smaller than Medium (that is, small).
Windows 8 phones older than Update 3 (released on October 14th, 2013) won’t apply the Bootstrap media queries correctly, meaning that pages using responsive classes may break. The issue along with a (short) fix is detailed in the Bootstrap 4 documentation.
- Linux操作系統應用編程
- 混沌工程實戰:手把手教你實現系統穩定性
- Instant Optimizing Embedded Systems using Busybox
- 8051軟核處理器設計實戰
- Linux使用和管理指南:從云原生到可觀測性
- Windows 7案例教程
- Learning Magento 2 Administration
- Linux命令行大全(第2版)
- 計算機系統:基于x86+Linux平臺
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)
- Linux從入門到精通(視頻教學版)
- 電腦辦公(Windows10+Office2016)從新手到高手
- Instant Responsive Web Design
- Administering ArcGIS for Server
- 鴻蒙應用開發實戰