Hiding Elements in Responsive Layouts with Bootstrap
As you've noticed, Bootstrap offers native support for collapsing navigation menu items on smaller screens. However, you may also want to conceal other elements on the page in similar situations.
Introducing Bootstrap's Visibility Classes
To address this need, Bootstrap provides a set of visibility classes that allow you to control the presence of elements based on the screen size. These classes include:
Usage
To hide an element on a small screen, simply add the appropriate hidden class to it. For instance, to hide the navigation pills you mentioned, you could use the following:
<code class="html"><ul class="nav nav-pills navbar-right hidden-sm"> ... </ul></code>
Additional Options
In Bootstrap 4, there are two additional types of visibility classes:
Note: Older versions of Bootstrap used classes like .hidden-phone and .visible-tablet, which are now obsolete.
Conclusion
By utilizing Bootstrap's visibility classes, you can effectively manage the display of elements on different screen sizes. This versatility allows you to create responsive layouts that adapt gracefully to varying device dimensions.
The above is the detailed content of How to Hide Elements in Responsive Layouts using Bootstrap?. For more information, please follow other related articles on the PHP Chinese website!