Introduction
When building a web application, creating cards is an essential part of the design process. In Bootstrap, you can easily create a card using the card component. By default, a card in Bootstrap has no shadow, but you can add a shadow on hover to give the card more depth and visual interest. In this article, we will show you how to create a shadow on hover class on a Bootstrap card with code examples.
How to Create a Shadow on Hover Class
To create a shadow on hover class, you need to use CSS. First, you need to create a class that defines the shadow you want to display when the user hovers over the card. Then, you need to use JavaScript to attach this class to the card element when the user hovers over it.
Here is an example of a shadow on hover class in CSS:
.shadow-hover:hover {
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
This class defines a shadow that is 0 pixels away from the top, 10 pixels away from the right, 20 pixels away from the bottom, and 0 pixels away from the left. The shadow color is a semi-transparent black, and the opacity is controlled using the RGBA (Red, Green, Blue, Alpha) values.
Next, you need to use JavaScript to attach this class to the card element when the user hovers over it. Here is an example of how to do this in jQuery:
$(".card").hover(function() {
$(this).addClass("shadow-hover");
}, function() {
$(this).removeClass("shadow-hover");
});
This code uses the jQuery hover() method to attach the shadow-hover class to the card element when the user hovers over it, and remove the class when the user stops hovering.
Example
Here is an example of a Bootstrap card with a shadow on hover class:

Card Title
Some quick example text to build on the card title and make up the bulk of the card’s content.
Conclusion
In this article, we have shown you how to create a shadow on hover class on a Bootstrap card with code examples. By using CSS and JavaScript, you can add visual interest to your cards and make them more engaging for your users. Whether you are building a portfolio, a blog, or any other type of web application, adding a shadow on hover to your cards
Cards in Bootstrap
Cards are a flexible and extensible content container in Bootstrap. They are used to display a variety of content, such as text, images, links, and buttons, in a compact and organized manner. Cards are built using HTML, CSS, and JavaScript and are part of the Bootstrap user interface (UI) components.
Cards have a header, body, and footer, and each of these sections can contain different types of content. The header section typically contains a title, and the body section can contain text, images, and other types of content. The footer section can contain additional information or actions, such as links or buttons.
Cards can be customized using CSS and JavaScript to fit the style and functionality of your web application. For example, you can add a shadow on hover, as we discussed in this article, or you can change the color, size, and border of the card to match your brand.
Box Shadow in CSS
The box-shadow property in CSS is used to add a shadow to an element, such as a card. The shadow can be positioned and styled to match the look and feel of your web application. The syntax for the box-shadow property is:
box-shadow: [horizontal offset] [vertical offset] [blur radius] [spread radius] [color];
The horizontal and vertical offset define the position of the shadow relative to the element. The blur radius defines the blurriness of the shadow, and the spread radius defines the size of the shadow. The color value defines the color of the shadow, which can be specified as a color keyword, hexadecimal value, RGB value, or RGBA value.
By using the box-shadow property in CSS, you can add depth and visual interest to your web applications and make them more engaging for your users.
jQuery
jQuery is a fast, small, and feature-rich JavaScript library. It makes it easy to traverse HTML documents, handle events, create animations, and perform Ajax interactions. jQuery is one of the most widely used libraries for JavaScript, and it is supported by many popular web applications and frameworks, including Bootstrap.
In this article, we used jQuery to attach the shadow-hover class to the card element when the user hovers over it. By using jQuery, we can add interactivity to our web applications and make them more engaging for our users. jQuery also makes it easy to write cross-browser compatible code, as it takes care of many cross-browser compatibility issues for us.
In conclusion, by combining the power of Bootstrap, CSS, and jQuery, you can create professional and engaging web applications that look and work great on all devices.
Popular questions
- What is a shadow on hover class in Bootstrap?
A shadow on hover class in Bootstrap is a CSS class that adds a shadow effect to a card element when the user hovers over it. This class can be used to create a more engaging and interactive user experience in your web applications.
- What is a card in Bootstrap?
A card in Bootstrap is a flexible and extensible content container that is used to display a variety of content, such as text, images, links, and buttons, in a compact and organized manner. Cards are part of the Bootstrap user interface (UI) components and can be customized using CSS and JavaScript to fit the style and functionality of your web application.
- How do you add a shadow on hover effect to a card in Bootstrap?
To add a shadow on hover effect to a card in Bootstrap, you need to create a CSS class that adds a box-shadow property to the card when the user hovers over it. You can also use jQuery to attach the shadow-hover class to the card element when the user hovers over it.
- What is the syntax for the box-shadow property in CSS?
The syntax for the box-shadow property in CSS is:
box-shadow: [horizontal offset] [vertical offset] [blur radius] [spread radius] [color];
The horizontal and vertical offset define the position of the shadow relative to the element. The blur radius defines the blurriness of the shadow, and the spread radius defines the size of the shadow. The color value defines the color of the shadow, which can be specified as a color keyword, hexadecimal value, RGB value, or RGBA value.
- What is jQuery and how does it relate to Bootstrap?
jQuery is a fast, small, and feature-rich JavaScript library that makes it easy to traverse HTML documents, handle events, create animations, and perform Ajax interactions. jQuery is one of the most widely used libraries for JavaScript and is supported by many popular web applications and frameworks, including Bootstrap.
In the context of this article, we used jQuery to attach the shadow-hover class to the card element when the user hovers over it. By using jQuery, we can add interactivity to our web applications and make them more engaging for our users. jQuery also makes it easy to write cross-browser compatible code, as it takes care of many cross-browser compatibility issues for us.
Tag
Interactivity.