Using Bootstrap's `.invisible` Class: Hiding Elements Without Affecting Layout
Learn how to use Bootstrap's `.invisible` utility class to hide HTML elements without affecting the page layout. This tutorial explains the difference between `.invisible` and `display: none;`, demonstrates its usage, and highlights its benefits in creating responsive and dynamic web pages.
Using Bootstrap's `.invisible` Class
Bootstrap's `.invisible` class is a utility class that provides a simple way to hide an element without affecting the document layout. This is different from using `display: none;`, which removes the element entirely from the document flow.
How `.invisible` Works
The `.invisible` class sets the `visibility` property to `hidden`. This makes the element invisible, but it still occupies space in the layout. This is useful when you need to hide an element temporarily or conditionally without disrupting the surrounding content.
Syntax and Usage
You can use the `.invisible` class directly in your HTML, or you can use it as a mixin within your Sass files. Here are the basic ways to use it:
Directly in HTML
Simply add the class to the element you wish to hide:
<div class="invisible">This text is hidden, but still takes up space.</div>
As a Sass Mixin
If you're using Sass, you can create a mixin to apply the `.invisible` style:
@mixin invisible {
visibility: hidden;
}
.my-element {
@include invisible;
}