Hover effects
Bootstrap 5 Hover effects
MDB hover effect appears when the user positions the computer cursor over an element without activating it. Hover effects make a website more interactive.
However, we don't recommend that you mix hover effects with functional elements (like a drop-down on hover or hidden buttons visible only after hovering) because such an approach isn't mobile-friendly.
MDB is a mobile-first framework, so we attach great importance to making each component easy to use for touch screens.
That's why our hover effects are gentle and decorative.
Basic example
Here is the most common example of hover effects usage - an image changed to link with an additional ripple effect on click.
Additionally, we added shadows and rounded corners and also changed ripple color to light via
data-mdb-attribute
.
<div
class="bg-image hover-overlay shadow-1-strong rounded"
data-mdb-ripple-init
data-mdb-ripple-color="light"
>
<img src="https://mdbcdn.b-cdn.net/img/new/fluid/city/113.webp" class="w-100" alt="Louvre" />
<a href="#!">
<div class="mask" style="background-color: hsla(0, 0%, 98%, 0.2)"></div>
</a>
</div>
Types
In MDB there are 3 types of the hover effects: overlay, zoom and shadow.
Overlay
Overlay is an effect that covers with color and defined level of opacity the entire image. The same as with mask you can change the color and opacity by manipulating HSLA code.
Our overlay hover effect relies on masks. Have a look at our masks docs to learn more.
Add .hover-overlay
class to to apply the hover effect.
Then manipulate HSLA code to change the color of the overlay.
hsla(217, 89%, 51%, 0.5)
hsla(276, 98%, 61%, 0.2)
hsla(144, 100%, 36%, 0.78)
hsla(349, 94%, 58%, 0.34)
hsla(0, 0%, 98%, 0.35)
hsla(195, 83%, 58%, 0.3)
You can even set a fancy gradient as an overlay.
<div class="bg-image hover-overlay">
<img src="https://mdbcdn.b-cdn.net/img/new/standard/city/053.webp" class="w-100" />
<div
class="mask"
style="
background: linear-gradient(
45deg,
hsla(168, 85%, 52%, 0.5),
hsla(263, 88%, 45%, 0.5) 100%
);
"
></div>
</div>
Zoom
To apply zoom hover effect you have to use slightly different, but simpler syntax.
You only need to add .hover-zoom
class to the .bg-image
element.
<div class="bg-image hover-zoom">
<img src="https://mdbcdn.b-cdn.net/img/new/standard/city/053.webp" class="w-100" />
</div>
Shadow
Shadow hover effect is even simpler. Simply add .hover-shadow
class to any
element to apply the effect.
<img
src="https://mdbcdn.b-cdn.net/img/new/standard/city/041.webp"
class="w-100 hover-shadow"
alt="Hollywood Sign on The Hill"
/>
Mixing effects
You can freely mix all the effects with each other. However, be careful not to overdo it. MDB adheres to the principle of minimalism and subtlety.
<div class="bg-image hover-overlay hover-zoom hover-shadow ripple">
<img src="https://mdbcdn.b-cdn.net/img/new/fluid/city/113.webp" class="w-100" />
<a href="#!">
<div class="mask" style="background-color: hsla(195, 83%, 58%, 0.2)"></div>
</a>
</div>
Overlay over mask
If you want to put a text on the image and you need a proper contrast, but still you wish to have hover effect, you can apply overlay on the already existing mask.
<div class="bg-image ripple" data-mdb-ripple-color="light">
<img src="https://mdbcdn.b-cdn.net/img/new/standard/city/053.webp" class="w-100" />
<a href="#!">
<div class="mask" style="background-color: hsla(0, 0%, 0%, 0.4)">
<div class="d-flex justify-content-center align-items-center h-100">
<p class="text-white mb-0">Can you see me?</p>
</div>
</div>
<div class="hover-overlay">
<div class="mask" style="background-color: hsla(0, 0%,98%, 0.2)"></div>
</div>
</a>
</div>
CSS variables
// .hover-overlay
--#{$prefix}image-hover-transition: #{$image-hover-overlay-transition};
// .hover-zoom
--#{$prefix}image-hover-zoom-transition: #{$image-hover-zoom-transition};
--#{$prefix}image-hover-zoom-transform: #{$image-hover-zoom-transform};
// .hover-shadow
--#{$prefix}image-hover-shadow-transition: #{$image-hover-shadow-transition};
--#{$prefix}image-hover-shadow-box-shadow: #{$image-hover-shadow-box-shadow};
// .hover-shadow-soft
--#{$prefix}image-hover-shadow-box-shadow-soft: #{$image-hover-shadow-box-shadow-soft};
SCSS variables
$image-hover-overlay-transition: all 0.3s ease-in-out;
$image-hover-zoom-transition: all 0.3s linear;
$image-hover-zoom-transform: scale(1.1);
$image-hover-shadow-transition: $image-hover-overlay-transition;
$image-hover-shadow-box-shadow: $box-shadow-4-strong;
$image-hover-shadow-box-shadow-soft: $box-shadow-5;