Applying CSS gradient hover effect on images of various sizes

I have a grid with 20 different pictures of various sizes created using bootstrap. Currently, I am displaying only 3 grid elements on my example page. I would like to implement a hover effect on these images similar to the gradient effect shown in this example but without the button.

I've attempted to apply this effect to my own image, however, I'm facing issues in making it work. Can anyone identify what I might be doing wrong? You can view the demo here.

This is the current code snippet from my demo:

body {
      background-color: #f5f5f5;
    }
    /* Set width between grid elements */
    .small-padding.top {
       padding-top:10px;
    }

    .small-padding.bottom {
        padding-bottom:10px;
    } 
    .small-padding.left {
        padding-left:5px;
    }

    .small-padding.right {
        padding-right:5px;
    }
    .margin_bottom {
      margin-bottom: 10px;
    }
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    .img-responsive { 
        height: 100%;
    }
    /* Position of buttons/text in a single grid element */
    .inner-wrapper {
      text-align: center;
      background: none;
    }
    .centered {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .bottom-right {
        position: absolute;
        bottom: 8px;
        right: 16px;
    }

    .bottom-left {
        position: absolute;
        text-align: left
        bottom: 8px;
        left: 16px;
    }
    /* Color styling for text */
    .dark-font {
      color: #333;
    }
    .light-font {
      color: #fff;
    }
   
    /* Set full width on columns */
    @media (max-width: 768px) {
      .img-responsive {
        width: 100%;
        }
      .btn-success {
        width: fit-content;
      }

    }

    @media (max-width: 991px) {
      h3 {
        font-size: 1.2em;

      }
    }
.image-overlay {
    position:relative;

    display:inline-block;
}
.overlay {
    position:absolute;
    transition:all .3s ease;
    opacity:0;
    transition:1.9s;
    background: #00b1bab8;
}
.image-overlay:hover .overlay {
    opacity:1;
}
.overlayFade {
  
    top:0;
    background: rgba(27, 27, 27, 0.5);

}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>TEMPLATE</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<head>

</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div align="center">
                <div>
                    <div class="image-overlay">
                        <img src="http://ercsirendelo.hu/_userfiles_/probarendelo/prevencio.jpg" alt="img" >
                        <div class="overlay overlayFade">
                            

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-8 margin_bottom">
                    <div class="image-overlay">
                  <!-- 770x480-->
                        <img src="https://d3j0sq6zklqdqq.cloudfront.net/photos/2017/03/06/107-40070-gilmore-girls-1488831826.jpg" alt="5" class="img-responsive" />
                        <div class="overlay overlayFade"></div>
                        <div class="inner-wrapper bottom-left">
                          <h3 class="light-font">Looking for having a good time</h3>
                          <span class="light-font">Here is where you should look</span>
                            <!--<button class="btn btn-success btn-lg">Read More</button>-->
                        </div>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="row">
                        <div class="col-sm-12 margin_bottom">
                          <!-- 430x235-->
                            <div class="image-overlay">
                                <img src="https://www.photolakedistrict.co.uk/wp-content/uploads/Daffodil-Winter-Wedding-Photo-Grasmere.jpg" alt="5" class="img-responsive" />
                                <div class="overlay overlayFade"></div>
                                <div class="inner-wrapper bottom-right">
                                <!--<button class="btn btn-success">Read More</button>-->
                            </div>
                        </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12 margin_bottom">
                          <!-- 430x235-->
                            <div class="image-overlay">
                                <img src="http://ercsirendelo.hu/_userfiles_/probarendelo/prevencio.jpg" alt="5" class="img-responsive" />
                                <div class="overlay overlayFade"></div>
                                <div class="inner-wrapper bottom-right">
                                <!--<button class="btn btn-success">Read More</button>-->
                            </div>
                          </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Answer №1

Revise the content in the .overlayFade class by including properties for left, right, and bottom.

.overlayFade {
    background: rgba(56, 56, 56, 0.7);
    top: 0;
    /* This is an example */
    bottom: 0;
    left: 0;
    right: 0;
}

Answer №2

To achieve the desired effect, simply incorporate the following code snippet into your stylesheet:

.image-overlay:hover .img-responsive {
opacity: 0.5;
}

Answer №3

To specify dimensions, simply provide either the height or width like so:

.overlayFade{width: 100%; height: 100%;}

I trust this information proves useful.

If you require additional clarification, please feel free to reach out.

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

Is it possible to change button behavior based on input values when hovering?

Currently, I am attempting to create a webpage where users can input two colors and then when they press the button, a gradient of those two colors will appear on the button itself. <!doctype html> <html> <head> <script src=&apos ...

An issue with type conversion arises in Visual Basic when trying to access data from an HTML

I'm currently working with an HTML table that allows for dynamically adding and deleting rows with text-input's in the cells using JavaScript. Instead of ASP.NET TextBox controls, I am sticking to traditional HTML because I believe rows containin ...

Is Swiper carousel navigation secretly operating without being seen?

I've got a website that utilizes the Swiper carousel from SwiperJS, find it here: An issue I am facing is that the navigation elements are invisible but functional, with the pagination feature unaffected. This peculiar behavior is observed only in Sa ...

Using CSS in React does not override the CSS preview in Ant Design for React

Working with Tables using antD has been quite an experience. By default, hovering over a Table Row in antD triggers a subtle gray color transition as a highlight. However, I wanted to switch things up and change the color to something different. My attempt ...

Cleaning up checkbox names by removing unnecessary characters

I'm having an issue with unnecessary characters in the names of checkboxes. There is a certain line var string = "<div class="blblb"><input type="checkbox" name="dasdasads"><input type="checbox" name="adsdsada"></div>"; The ...

Is there a way for me to determine if a user has engaged with a form?

I'm surprised by how difficult it was to find information on this topic through Google. Currently, my struggle lies in wanting my form fields to change color based on validity only after the user has interacted with the form. I don't want invali ...

Identifying the precise image dimensions required by the browser

When using the picture tag with srcset, I can specify different image sources based on viewport widths. However, what I really need is to define image sources based on the actual width of the space the image occupies after the page has been rendered by th ...

What is the method for utilizing the variable from express in HTML?

Currently, I am working with Express and have the following code: app.get('/', requiresAuth(), (req, res) => res.sendFile('/db_auth_site/index.html', { title: 'Hey', message: 'Hello there!' }) ); I am trying ...

Switch between 2 sections with a click of a button (Implementing Javascript, HTML, and CSS)

There are two divs with different content inside, and I want to toggle between them using a button. Here are my two divs with classes "step1Content" and "step2Content" respectively. <div class='step1Content'> Content1 </div> <div ...

Update the jQuery Mobile components on the page by refreshing them after dynamically adding them using AJAX and PHP

I have developed a PHP script that dynamically renders three form elements for each entry in a database. The script generates HTML output similar to the following example: <!-- Entry 1 --> <div data-role="fieldcontain"> < ...

What steps are involved in configuring Meteor-Angular with Twitter Bootstrap?

I'm currently struggling with setting up Twitter Bootstrap in my Meteor-Angular project. Here's what I've done so far: Installed Bower meteor add mquandalle:bower Added a dependency to bower.json: { ... "dependencies": { "a ...

The Vue design is not being reflected as expected

Encountering a peculiar issue where the style in my Vue component is not being compiled and applied alongside the template and script. Here's the code snippet: To achieve an animated slide fade effect on hidden text upon clicking a button, I've ...

Issue with Swiper JS: The buttons on pages three and beyond are unresponsive

I'm having trouble with the functionality of the "Back" button on pages 2 and 3 of my website. Can anyone help me figure out why it's not working? My goal is to create a website that resembles a game menu, similar to Deus Ex The Fall. I'm u ...

How can you convert an epoch datetime value from a textbox into a human-readable 24-hour date format

I have an initial textbox that displays an epoch datetime stamp. Since this format is not easily readable by humans, I made it hidden and readonly. Now, I want to take the epoch value from the first textbox and convert it into a 24-hour human-readable da ...

Creating a Dynamic List in SASS and Stylus

Working with both SASS and Stylus has been quite challenging for me, especially when trying to append elements to a list. Here's an example: $names: adam john wynn mason kuroir .photos @each $name in $names .photo-#{$name} background: i ...

What is the best practice for incorporating CSS and JavaScript files into a PHP template?

I've created a basic template for my PHP website, but I'm struggling to find the best way to include my CSS and JavaScript files. Take a look at my index.php file below: <?php include'core/template.php'; $temp=new Template(); $sett ...

Declare webpage as manager for mailto links

One interesting feature I've observed in various web-based email providers is the ability to add the website as the default mailto links handler in browsers like Firefox and Chrome. This means that when clicking on a mailto: link, it will automaticall ...

Some browsers are failing to display the navigation bar on my website

After working on my website, www.alexanderpopov.org, I encountered an issue with the navigation bar disappearing on some computers and browsers. I'm using css to style it, but the problem persists. Below is the HTML code for your reference. Any advice ...

What is the best way to pass URLs for dynamic anchor tags to the jQuery hover() function?

Hey there! My goal is to create a list of links in HTML using anchor tags: <a href="/path/100" id="clickme">One link</a> <a href="/path/101" id="clickme">Second link</a> <a href="/path/102" id="clickme">Third link</a> & ...

javascript jquery chosen not functioning properly

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JavaScript</title> </head> <body> <h1 id="hey">List King</h1> <div class="Select-DB"> <select id="DB" class="chosen ...