simultaneous image hover effect for all images

I am experiencing an issue with my CSS and Bootstrap hover effect. The overlay tags are enclosed within a div class, but they all hover simultaneously. Each overlay belongs to a different Bootstrap grid, yet the effect extends even to the empty spaces between the photos. Any assistance on how to resolve this would be greatly appreciated. Thank you.

HTML:

<div class="container">
  <div class="row">
      <div class="col-md-12 text-align-center">
        <h2 class="bold_font">BROWSE OUR CARDS</h2><br>
      </div>

      <div class="col-md-4 col-xs-12">
        <a href="cards/list.php?tn=beauty">
          <img class="img-responsive" src="img/_stock_mwc_beauty.jpg">
          <div class="overlay">
            <div class="overlay-content">
              <img src="img/icon-beauty-white.png" class="img-responsive center-block">
              <div class="spacer overlay-text">BEAUTY</div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-md-4 col-xs-12">
        <a href="cards/list.php?tn=health">
          <img class="img-responsive" src="img/_stock_mwc_health.jpg">
          <div class="overlay">
            <div class="overlay-content">
              <img src="img/icon-health-white.png" class="img-responsive center-block">
              <div class="spacer overlay-text">HEALTH</div>
            </div>
          </div>
        </a>
      </div>

      <div class="col-md-4 col-xs-12">
        <a href="cards/list.php?tn=wellness">
          <img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
          <div class="overlay">
            <div class="overlay-content">
              <img src="img/icon-wellness-white.png" class="img-responsive center-block">
              <div class="spacer overlay-text">WELLNESS</div>
            </div>
          </div>
        </a>
      </div>
  </div>
</div>

CSS:

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color: #f08300;
}

.container:hover .overlay {
  opacity: 1;
}

.overlay-content {
  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;
}

.spacer {
    margin: 20px 0px 20px 0px;
}

For further information, here is the link to my JSFiddle where I have added placeholder images: http://jsfiddle.net/cnkgqhdw/1/

Answer №1

Instead of applying the hover effect to the container, try targeting the columns directly! Just modify .container:hover to .col-md-4:hover.

To maintain proper spacing, you can leverage Bootstrap's built-in spacing system. For your scenario, you can create a default margin by adding the class mx-3 to the overlay element.

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  opacity: 0;
  transition: .5s ease;
  background-color: #f3a64c;
}

.col-md-4:hover .overlay {
  opacity: 1;
}

.overlay-content {
  color: white;
  font-size: 30px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}

.exact-center {
  text-align: center;
  vertical-align: middle;
}

.spacer {
  margin: 20px 0px 20px 0px;
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  
<div class="container">
  <div class="row">
    <div class="col-md-12 text-align-center">
      <h2 class="bold_font">BROWSE OUR CARDS</h2><br>
    </div>

    <div class="col-md-4 col-xs-12">
      <img class="img-responsive" src="img/_stock_mwc_beauty.jpg">
      <div class="overlay mx-3">
        <div class="overlay-content">
          <img src="img/icon-beauty-white.png" class="img-responsive center-block">
          <div class="spacer overlay-text">BEAUTY</div>
        </div>
      </div>
    </div>

    <div class="col-md-4 col-xs-12">
      <img class="img-responsive" src="img/_stock_mwc_health.jpg">
      <div class="overlay mx-3">
        <div class="overlay-content">
          <img src="img/icon-health-white.png" class="img-responsive center-block">
          <div class="spacer overlay-text">HEALTH</div>
        </div>
      </div>
    </div>

    <div class="col-md-4 col-xs-12">
      <img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
      <div class="overlay mx-3">
        <div class="overlay-content px-3">
          <img src="img/icon-wellness-white.png" class="img-responsive center-block">
          <div class="spacer overlay-text">WELLNESS</div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №2

The current configuration is set to activate the :hover on the .container element, representing the entire row. To make it work properly, include a class for your card and apply .card:hover

Answer №3

When you hover over the entire container, every element within it will also receive the hover effect.

To avoid this, it is recommended to assign a specific class to the:

<a class="item" href=""> 

and then apply the hover effect to that class:

.item:hover {
  //add your styling here
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The background image on my CSS is not showing up

I just added the file to my git repository and shared the link here. Is there a specific way to do this? html{ background-image:url("https://github.com/vindhya97/images/blob/master/pinkbackground.jpg"); } ...

Discrepancy in Table Alignment

I seem to be encountering an issue with the alignment of text in my table. It appears that there are differences in content among the columns, causing the misalignment. I have tried adding white-space within each table, but it doesn't solve the proble ...

What impact does the order of the element I'm specifying in my .css file have on its appearance after being rendered?

(An update has been added below) In my project, I am working with a .css file and an index.html document. The goal is to create a panel of buttons on the screen [to prototype the usability of a touchscreen interface], with each button assigned a specific ...

Responsive Navigation Menu using Bootstrap Framework for mobile devices

I am encountering an issue with my bootstrap navbar where the button does not appear on the mobile version. This is happening while testing on my Windows Phone. Below is the code for my navbar: <nav class="navbar navbar-default navbar-fixed-top" ro ...

Transitioning the font stack from SCSS to JSS (cssinjs)

We are currently implementing a variety of custom fonts with different weights for various purposes. With our entire stack now using Material UI with JSS theming and styling, we aim to eliminate the remaining .scss files in our folder structure. All the f ...

CSS outline not displaying correctly in latest version of Internet Explorer

Currently delving into the UI of my web design project. I have come across an issue where the outlined feature in a specific div is not displaying properly in IEv11. Below is a snippet of the CSS code causing the problem... .samp-banner:focus, #samp- ...

JavaScript slice() method displaying the wrong number of cards when clicked

In my code, I have a section called .registryShowcase. This section is designed to display logos and initially shows 8 of them. Upon clicking a button, it should load the next set of 8 logos until there are no more left to load (at which point the button ...

The functionality of my website is not optimized for viewing on iPhones

While designing a responsive website that looks great on most devices, I noticed some issues with iPhones. The layout breaks in two specific ways on these devices. View Galaxy Screenshot View Sony Screenshot The menu doesn't scale properly on iPho ...

Is there a method for redirecting my page to a specific href link without triggering a page reload?

This is my HTML code. <a href="http://127.1.1.0:8001/gembead/emstones.html?car=36">Car</a> I am trying to redirect to a specific page with parameters without fully reloading the current page. Is there a way to achieve this task? I believe the ...

The HTML Style for implementing HighChart title text does not work when exporting files

I have inserted the <br/> and &nbsp; HTML tags into the HighChart titles. The style changes successfully appear in the chart view, but unfortunately, when exported as PNG or JPEG images, the text style fails to apply in the resulting images. To s ...

The background of the wrapper div refuses to expand beyond the original size of the browser window

I'm currently in the process of developing a website, focusing on establishing the fundamental structure of my design to facilitate the addition of content and allow for the dynamic expansion of the div based on the length of the content. Nevertheless ...

I am attempting to assign a default value to a TextField by retrieving data from a GetMapping call in React, however, the value is not being successfully set

I am facing an issue with setting a default value for a TextField in my code. Even though I am trying to populate it with data from a GetMapping call, the value is not being set as expected. Here is the JSON response I receive from the API call: { "id": 1 ...

What is the best way to maintain the height of a background image while cropping it horizontally and resizing the browser?

My code looks like this:- HTML <div id="header-main"></div> CSS #header-main { background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/planet-bg.jpg); background-position: center; background-size ...

Ways to extract all hyperlinks from a website using puppeteer

Is there a way to utilize puppeteer and a for loop to extract all links present in the source code of a website, including javascript file links? I am looking for a solution that goes beyond extracting links within html tags. This is what I have in mind: a ...

Switching over to a stored procedure

I have been using a query string for the jQuery Autocomplete plugin, but I think it would be better to switch to a stored procedure. However, when I tried to do so, it didn't work. Can anyone provide guidance on how to convert my code? Original ASHX ...

Tips for updating the background color of a dropdown menu in the navigation bar

I am attempting to increase the size of the dropdown menu and change its background color. Currently, I can only modify the color of the links and the surrounding area. .navbar a { width: 125px; text-align: center; ...

The background color in CSS remains stagnant, refusing to change despite

Can someone help me figure out why the background color isn't changing in my simple code? I've double-checked that the external CSS is properly linked because the text color of h1 is changing. <!DOCTYPE html> <html> < ...

Attempting to execute a PHP script through a JavaScript if statement

I have a form that requires validation with JavaScript. In one of the if statements, after all other conditions have been validated, I want to execute my PHP script that updates an SQL database with one of the passwords. Here is the final validation code: ...

Looking to troubleshoot the selenium error in a loop, specifically the InvalidSelectorException that states: "invalid selector: Unable to find element with the specified xpath"?

I have been attempting to create a for loop in selenium that checks if certain buttons on a website are clickable, clicks on them, and refreshes the page until they are. However, I am encountering an error with my Xpaths as shown below (InvalidSelectorExce ...

Explore relevant Pill information dynamically based on the image that was clicked in Angular

In this particular situation: Using Angular 1.7.2 Utilizing Bootstrap 3 Encountering some challenges after the user interacts with the image: Current Behavior: Upon clicking any image, a modal window appears displaying relevant content. If image 1 is ...