How to Hide Elements in Responsive Layouts using Bootstrap?

Barbara Streisand
Release: 2024-11-06 03:03:02
Original
813 people have browsed it

How to Hide Elements in Responsive Layouts using Bootstrap?

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:

  • visible-xs-block, hidden-xs: Hide elements on extra small devices (less than 768px).
  • visible-sm-block, hidden-sm: Hide elements on small devices (768px and above).
  • visible-md-block, hidden-md: Hide elements on medium devices (992px and above).
  • visible-lg-block, hidden-lg: Hide elements on large devices (1200px and above).

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>
Copy after login

Additional Options

In Bootstrap 4, there are two additional types of visibility classes:

  • hidden-*-up: Hides the element when the viewport is at the given breakpoint or wider.
  • hidden-*-down: Hides the element when the viewport is at the given breakpoint or smaller.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!