How to add a black hover to an image using bootstrap? Last Updated : 13 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Bootstrap is a popular CSS framework widely used by frontend developers to create interactive UI for web applications. Bootstrap is widely used because of its simplicity and ease to use. Bootstrap allows multiple utilities to make images interactive. One of these utilities can be changing the color of the image when hovered over. Hovering is basically moving the cursor over the image. The code snippet below demonstrates how to add a black hover to an image using bootstrap. First Approach: In this method, the content-overlay class specifies the required properties of the image while the mouse hovers over it. The background property in the content-overlay class specifies the opacity of the image when the user hovers over it. The content-details class specifies the set of properties that are used for the content displayed on top of the image when the mouse hovers over it. Example: HTML <!DOCTYPE html> <html> <head> <title></title> <!-- importing bootstrap cdn--> <link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity= "sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <style> /*setting the properties for container which contains the image */ .container { margin-top: 5px; } /*setting the properties for title*/ .title { color: #1a1a1a; text-align: center; margin-bottom: 10px; } /*setting the properties of content within the image*/ .content { position: relative; width: 90%; max-width: 400px; margin: auto; overflow: hidden; } /* rgb(0,0,0) indicates black and the fourth parameter is the opacity */ .content .content-overlay { /*setting 0.8 to 1 will turn the overlay opaque*/ background: rgba(0, 0, 0, 0.8); position: absolute; height: 99%; width: 100%; left: 0; top: 0; bottom: 0; right: 0; opacity: 0; /*transition time and effect*/ -webkit-transition: all 0.4s ease-in-out 0s; /*transition time and effect*/ -moz-transition: all 0.4s ease-in-out 0s; /*transition time and effect*/ transition: all 0.4s ease-in-out 0s; } /* setting hover properties */ .content:hover .content-overlay { opacity: 1; } .content-image { width: 100%; } /*setting image properties*/ img { box-shadow: 1px 1px 5px 1px rgba(0, 0, 0, 0.1); border-radius: 5px; } .content-details { position: absolute; text-align: center; padding-left: 1em; padding-right: 1em; width: 100%; top: 50%; left: 50%; opacity: 0; -webkit-transform: translate(-50%, -50%); -moz-transform: translate(-50%, -50%); transform: translate(-50%, -50%); /*transition time and effect*/ -webkit-transition: all 0.3s ease-in-out 0s; /*transition time and effect*/ -moz-transition: all 0.3s ease-in-out 0s; /*transition time and effect*/ transition: all 0.3s ease-in-out 0s; } .content:hover .content-details { top: 50%; left: 50%; opacity: 1; } .content-details h3 { color: #fff; font-weight: 500; letter-spacing: 0.15em; margin-bottom: 0.5em; text-transform: uppercase; } .content-details p { color: #fff; font-size: 0.8em; } </style> </head> <body> <div class="container"> <div class="content"> <div class="content-overlay"></div> <img class="content-image" src="https://media.geeksforgeeks.org/wp-content/uploads/20200325132558/download311.png" height="300px"> <div class="content-details"> <h3 class="content-title"> GeeksforGeeks </h3> <p class="content-text"> Hover out to view image </p> </div> </div> </div> </body> </html> Output: Before Hover: After Hover: Alternate approach: The second approach also deals with the hovering effect but here the hovering opacity is set to 1 which means the underlying image becomes completely hidden. The overlay class contains the set of specifications for the image when hovered over. The background color is set to black. The transition time and nature are also set. Example: HTML <!DOCTYPE html> <html> <head> <!--helps in scaling the web page according to the device screen size--> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .main-container { display: flex; flex-direction: column; position: relative; justify-content: center; align-items: center; width: 600px; } /*image class sets the properties of the image used*/ .image { display: block; width: 100%; height: auto; } /*overlay class sets the properties of the overlay image*/ .overlay { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; /*the transition time between the actual image to overlay*/ transition: 0.3s ease; /*ensures black hover on the image*/ background-color: black; } /*hovering property is set*/ .inner-container:hover .overlay { opacity: 1; } /*properties for the text on the overlay image*/ .text { color: white; font-size: 20px; position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); text-align: center; } </style> </head> <body> <div class="main-container"> <h2> Adding black color to image using the overlay class </h2> <p>Hover over the image to see the effect.</p> <div class="inner-container"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20200325132558/download311.png"> <div class="overlay"> <div class="text"> Hover out to view image </div> </div> </div> </div> </body> </html> Output: Before Hover: After Hover: HTML is the foundation of web pages and is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples. CSS is the foundation of web pages and is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples. Comment More infoAdvertise with us Next Article How to create full width container using bootstrap? S Shreyasi_Chakraborty Follow Improve Article Tags : Web Technologies Bootstrap Bootstrap-Misc Similar Reads Bootstrap Tutorial Bootstrap is a popular front-end framework for building responsive and mobile-first websites. It provides pre-designed CSS, JavaScript components, and utility classes to quickly create modern and consistent user interfaces.It Includes pre-built responsive grid systems for mobile-first design.Offers 4 min read Bootstrap 5 Tutorial Bootstrap 5 is a front-end framework that helps developers create responsive and visually appealing websites quickly and efficiently. Bootstrap 5 simplifies the process of web development with its intuitive design system and extensive components. This version includes improved responsiveness, stream 6 min read Bootstrap 4 Tutorial Bootstrap 4 is an open-source framework for creating responsive web applications. It is the most popular CSS framework for creating mobile-first websites. It is free to use we can directly integrate Bootstrap 4 into our project using CDN Links or with npm. Bootstrap 4 Tutorial is designed to help be 3 min read Bootstrap 5Bootstrap 5 IntroductionBootstrap is a free and open-source collection of CSS and JavaScript/jQuery code used for creating dynamic websites layout and web applications. Bootstrap is one of the most popular front-end frameworks which has really a nice set of predefined CSS codes. Bootstrap uses different types of classes to 4 min read Bootstrap 5 ProgressBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. A progress bar is used to display the progress of a process on a computer. A progress bar displays how much of the process is completed and how much is left. You can add a progress bar o 5 min read Bootstrap 5 ButtonsBootstrap 5 Buttons are pre-styled components in the Bootstrap framework, offering consistent design and functionality. They streamline development by providing ready-to-use button styles, sizes, and behaviors, ensuring a cohesive and responsive user interface across web applications with minimal CS 3 min read Bootstrap 5 BadgesBootstrap 5 Badges are small components used to highlight specific information, typically in lists or inline with other content. They provide visual cues through colored backgrounds and customizable text, helping to draw attention to key details or status indicators within a webpage or application. 2 min read Bootstrap 5 AlertsBootstrap 5 Alerts are customizable components used to convey important information to users. They come in various styles such as success, warning, danger, and info, providing visual feedback to users based on different actions or states within a web application. iframe { width: 100%; height: 450px; 2 min read Bootstrap 5 ModalBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. Modals are used to add dialogs to your site for lightboxes, user notifications, or completely custom content. Modals are built with HTML, CSS, and JavaScript. Theyâre positioned over eve 7 min read Bootstrap 4Bootstrap 4 IntroductionBootstrap is a free and open-source tool collection for creating responsive websites and web applications. It is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites. It solves many problems which we had once, one of which is the cross-browser compati 3 min read Bootstrap 4 | Grid SystemBootstrap Grid System allows up to 12 columns across the page. You can use each of them individually or merge them together for wider columns. All combinations of values summing up to 12 can be used. Grid Classes: Bootstrap grid system contains five classes which are listed below: .col- It is used f 3 min read Bootstrap 4 | TypographyTypography is a feature of Bootstrap for styling and formatting the text content. It is used to create customized headings, inline subheadings, lists, paragraphs, aligning, adding more design-oriented font styles, and much more. Bootstrap support global settings for the font stack, Headings and Link 3 min read Bootstrap 4 | ColorsText Colors: Bootstrap provides many classes to set the text color of an element. All classes of text colors are listed below: Example: This example uses text color class to set the color of text content. html <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap 2 min read Bootstrap 4 | TablesBootstrap provides a series of classes that can be used to apply various styling to the tables such as changing the heading appearance, making the rows stripped, adding or removing borders, making rows hoverable, etc. Bootstrap also provides classes for making tables responsive. Simple Table: The .t 9 min read Bootstrap 4 ImagesBootstrap 4 provides classes to style images responsively, including responsive images that automatically adjust the size based on screen width, image shapes such as rounded or circular, and image thumbnails with optional borders and captions, facilitating flexible and attractive image layouts. The 4 min read Bootstrap QuestionsHow to design Bootstrap Fullscreen Select feature for Mobiles ?In this article, we will learn how to design Bootstrap fullscreen select feature for mobile devices.It provides advanced HTML full screen select functionality.It provides in and out animations.It provides open and close events function callbacks.It provides CSS3 animated buttons, dropdowns and texts 3 min read How to use Top Navigation with Left Navigation Bar using Bootstrap?Using Top Navigation with Left Navigation Bar in Bootstrap means creating a layout with a responsive top navigation bar (typically for global site navigation) and a left sidebar for additional links or menus. This combines Bootstrapâs grid system, navbar classes, and custom CSS for layout management 4 min read How to put two columns one below other in sidebar in Bootstrap?To place two columns one below the other in a sidebar using Bootstrap, you can use Bootstrap's grid system. By setting up a vertical stacking of columns within a sidebar container, you ensure that the columns appear one below the other. This is achieved by using a single column width and placing the 5 min read How to always show first two rows in dynamic collapse using Bootstrap ?Bootstrap is an open-source front-end CSS framework used widely for the development of interactive websites. Bootstrap with HTML and JavaScript adds interactivity to the user interface. jQuery is a JS library used for the manipulation of HTML DOM, event handling, CSS animations, and Ajax. jQuery is 6 min read How to add a black hover to an image using bootstrap?Bootstrap is a popular CSS framework widely used by frontend developers to create interactive UI for web applications. Bootstrap is widely used because of its simplicity and ease to use. Bootstrap allows multiple utilities to make images interactive. One of these utilities can be changing the color 4 min read How to create full width container using bootstrap?Bootstrap offers two types of containers: fixed-width containers and full-width, fluid containers. The container-fluid class is used to create a full-width container that spans the entire width of the viewport, adjusting dynamically as the viewport size changes.Container Types in BootstrapFixed-Widt 3 min read How to fit the image into modal popup using Bootstrap?Modal plugin allows us to add a dialog popup window that is displayed on top of the current page. Bootstrap provides an easy, yet effective way to incorporate modal into our web pages. Modal can consist of any content along with a header and footer.Images can be fitted in modal popup using Bootstrap 2 min read Bootstrap ExamplesThe following Bootstrap section contains a wide collection of Bootstrap examples. These examples are categorized based on the topics including basics, directives, functions, and many more. Each example may contain multiple approaches to solve the problem. Table of Content CustomizeLayoutContentForms 4 min read Like