Hovering over an image with CSS for a cool effect - altering the background and text

I'm experimenting with creating a mouseover effect on images where the background becomes dimmer and text appears on top.

For example, you can take a look at this page and scroll down to see how the second set of images darken and display text when you hover over them.

Initially, I considered changing the image itself on mouseover, but I believe I can achieve the effect using CSS.

HTML

<div id="bottomWide">           
    <ul>
        <li>
            <img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt=""> 
                                <div>Some text here, style as needed</div>
        </li>
        <li>
            <img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
                                <div>Some text here, style as needed</div> 
        </li>

    </ul> 
</div>

CSS

#bottomWide{
    width:100%;
    margin:0 auto;


}

#bottomWide ul{
    margin:0;
    padding:0;
    /* For Mouse Over*/
    position: relative;
    display: inline-block;
}
#bottomWide li{
  list-style-type: none;
  display: inline-block;
    width:50%;
    text-align:justify;
    float: left;
}

#bottomWide img{
    width:100%;
}



#bottomWide li div{
    position: absolute;
    top: 0;
    left: 0;
    /* 100% will equal the dimensions of the image, as nothing else will be inside the .container */
    width: 100%;
    height: 100%;
    color: #fff;
    background-color: #000;
    opacity: 0;
    /* This will create the fade effect */
    transition: opacity 0.3s;
    -webkit-transition: opacity 0.3s;
    /* Include all required vendor prefixes for opacity and transition */
}

#bottomWide li div:hover {
    opacity: 0.7;
}

Answer №1

One approach would be to:

  • Create an absolutely positioned div on top of the image with a default opacity of 0 and a dark background. This div would contain your text. To achieve a fade in / fade out effect, avoid using display: none and display: block as CSS transitions do not support the display property.
  • Upon hover, increase the opacity to nearly 1 to reveal the text.
  • Implement a CSS transition for the opacity property to smoothly fade the background in and out.

For an example, check out http://jsfiddle.net/AEyW3/

Answer №3

It seems like they are utilizing the opacity attribute. By default, all images have an opacity of 1, so reducing it to something like .5 will give the impression of darkening the image.

Check out this Fiddle for more details.

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

Tips for avoiding divs from overlapping when the window size is modified

When I maximize the browser, everything aligns perfectly as planned. However, resizing the window causes my divs to overlap. Despite trying several similar posts on this issue without success, I have decided to share my own code. CODE: $(document).read ...

Ways to create a fixed button positioned statically at the bottom of a page

Currently, I am utilizing tailwind CSS to create a webpage with Next and Back buttons for navigation. However, an issue arises when there is minimal content on the page as the button adheres to the top. For visual reference, please view the image linked be ...

What could be causing the background image on my Jumbotron to fail to load?

Having some trouble with setting my image as the background of the Jumbotron. I've tried a few different approaches, but none seem to be working. It's not an issue with static loading because using img src directly into the Jumbotron section does ...

Switch up the background image when hovering over it

Could the proportions of the image be contributing to the issue at hand? #menu { background: black; width: 100%; height: 45px; } #menu ul { text-decoration: none; list-style-type: none; } #menu li { text-decoration: none; display: inline; font-size: ...

Why isn't my CSS button changing color on hover?

div ul li a.button:hover { text-color:#FF0000; background: #0040FF; } I have been attempting to create buttons that change color and text when hovered over. Despite trying different methods, the changes do not seem to be taking effect. Below is the co ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): https://i.sstatic.net/xcqaT.png EDIT: The layout on large scre ...

Displaying a Color Sample in a Grid

I'm currently working on a feature that allows users to select colors using the jQuery minicolor widget. I really like how the color swatch appears inside the widget, but I'm having trouble replicating that same look in a data table. When I try t ...

The number of TH elements does not match the number of columns in the table

Is there a way to make only one th span the full width of the table, even with 5 columns below? I want to color the background of the th to cover the entire width. However, since the rest of the table contains 5 columns, the single th only stretches acros ...

Is it possible to control my CSS using ModX Resources?

I have recently been experimenting with the ModX Revolution manager and had a question about converting my CSS into ModX Resources instead of files. I am interested in utilizing Templates and their variables as well. Do you know if this is possible? Also, ...

The FontAwesome icon is not showing up on this particular view, but it displays correctly on a

I'm facing a strange issue: one of my FontAwesome icons is not appearing on the view, even though all the other icons are working fine. I've been trying to figure out why. <a class="add-img fa fa-plus-circle" title="@SharedResources.Index.Add ...

Concerns with the dimensions of HTML thumbnails

view image description here I seem to be having an issue with the size of thumbnails on my website. The problem arises when a thumbnail with a long title is displayed, as it ends up taking up more space and affecting the layout. Is there a solution to ens ...

Using props as classnames in next.js applications

I am currently attempting to create a dynamic header for each page of my app that changes color based on the current page. Here is my approach: <Header className="headerBitcoin"></Header> My goal is to have the same header component ...

The static background and fixed header are locked in a perpetual battle

I am currently working on creating a fixed header that remains at the top of the page. However, I am facing an issue where the background seems to be overlapping and hiding the header. <style type="text/css> html, body {height:100%; margin:0; paddin ...

Issue with flexbox max-width property not being applied when resizing the page width

I'm struggling to make a flex box with max and min width properties work properly. When I reduce the page size, it ends up showing blank space instead of resizing. How can I troubleshoot this issue? .parent{ border: 1px solid red; width: 50%; ...

The initial navigation pill content failed to display in Bootstrap

I am experiencing an issue with my pills that have 4 tabs. Initially, when I reload the page, the content of the first tab does not show up. However, if I navigate to another tab and then back to the first tab, the content appears. Can anyone suggest a fix ...

When using a custom selection color to highlight underlined text, the underline becomes invisible

I am currently working on a website where I want to customize the text selection color. ::selection { background-color:#00ffff; } However, there seems to be an issue in this specific situation: p::after { content:"Try selecting the above elemen ...

Halt spread: descend in a bubble?

It seems that the issue at hand may not be related to propagation, but rather a design flaw. I have come across information suggesting that propagation problems tend to bubble up, however, let me explain my situation. I am working with a table edit grid. ...

Wrap link column data in a bootstrap table for a seamless display

Is there a way to make a link in a table cell wrap and respect the column width I provide? When data in a table cell is a link, it doesn't seem to let me specify the column width. How can this be achieved? <link href="https://cdn.jsdelivr.net/np ...

"Utilizing images within an iframe: A step-by-step guide

I'm trying to integrate an iframe into a phone image with a transparent background. However, I am unsure how to effectively mask the iframe so that it only appears within the boundaries of the phone image. .phone { display: block; position: r ...

Creating styles for different screen sizes including mobile devices, low-resolution desktops, and high-resolution desktops

One of the techniques I'm using involves analyzing both the horizontal and vertical screen dimensions to differentiate between mobile devices and desktops, as well as distinguish high-resolution from low-resolution desktop displays. In order to achie ...