CSS image replacement; won't render properly

I'm currently working on implementing a hover image swap effect for my website gallery. The CSS code I have so far is below. While the original images in my HTML file are displaying correctly, the hover functionality is not working as expected.

CSS:

#gallery img {
    max-height: 25%;
    margin: 10px 10px 10px 10px;
    float: right;
    border-radius: 17px 0 17px 0;
    border:2px solid #888888;   
    background-image: url(/images/ferrari.jpg);
    background-image: url(/images/dalmation.jpg);
    background-image: url(/images/hanauma.jpg);
    background-image: url(/images/aircraft-sunset.jpg);
    background-image: url(/images/crab.jpg);
    background-image: url(/images/moth.jpg);
    background-image: url(/images/lake.jpg);
    background-image: url(/images/flag.jpg);
    background-image: url(/images/aircraft-landing.jpg);
    background-image: url(/images/tarantula.jpg);
    display: block;
}

#gallery img :hover {
    visibility: hidden;
}

------------------>HTML

    <ul id="gallery"> 
    <li><img src="/images/ferrari-gray.jpg" alt=""/></li>
    <li><img src="/images/dalmation-gray.jpg" alt=""/></li>
    <li><img src="/images/hanauma-gray.jpg" alt=""/></li>
    <li><img src="/images/aircraft-sunset-gray.jpg" alt=""/></li>
    <li><img src="/images/crab-gray.jpg" alt=""/></li>
    <li><img src="/images/moth-gray.jpg" alt=""/></li>
    <li><img src="/images/lake-gray.jpg" alt=""/></li>
    <li><img src="/images/flag-gray.jpg" alt=""/></li>
    <li><img src="/images/aircraft-landing.jpg" alt=""/></li>
    <li><img src="/images/tarantula.jpg" alt=""/> </li>
</ul>

Answer №1

You have the option of utilizing a @keyframes animation to accomplish this task. However, achieving a smooth transition may require implementing some clever techniques involving other elements or pseudo-elements in conjunction with adjusting opacity levels.

@keyframes changeImage {
    0%   { background-image: url(/images/tarantula.jpg); }
    10%  { background-image: url(/images/aircraft-landing.jpg); }
    20%  { background-image: url(/images/flag.jpg); }
    30%  { background-image: url(/images/lake.jpg); }
    40%  { background-image: url(/images/moth.jpg); }
    50%  { background-image: url(/images/crab.jpg); }
    60%  { background-image: url(/images/aircraft-sunset.jpg); }
    70%  { background-image: url(/images/hanauma.jpg); }
    80%  { background-image: url(/images/dalmation.jpg); }
    90%  { background-image: url(/images/ferrari.jpg); }
}
@-webkit-keyframes changeImage {
    0%   { background-image: url(/images/tarantula.jpg); }
    10%  { background-image: url(/images/aircraft-landing.jpg); }
    20%  { background-image: url(/images/flag.jpg); }
    30%  { background-image: url(/images/lake.jpg); }
    40%  { background-image: url(/images/moth.jpg); }
    50%  { background-image: url(/images/crab.jpg); }
    60%  { background-image: url(/images/aircraft-sunset.jpg); }
    70%  { background-image: url(/images/hanauma.jpg); }
    80%  { background-image: url(/images/dalmation.jpg); }
    90%  { background-image: url(/images/ferrari.jpg); }
}

An alternative approach (potentially the more effective one) would be to utilize javascript.

Answer №2

In order to properly define a hover effect, there should be no space between:

img:hover 

I'm unsure about the use of multiple background images in this context.

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

Optimal methods for arranging images in a list with CSS

I am trying to create a grid layout for a list of images using CSS. Here is the HTML code I have: <ul id='feat-products'> <li><img id='feat-product-1'></li> <li><img id='feat-product-2&apos ...

No feedback received after sending keys using Selenium

Whenever I execute my code using PhantomJS and Selenium, the result appears to be correct. However, when it comes to using send_keys function, the code gets stuck without any errors, answers, or progress. I am puzzled and eager to find out why this is ha ...

Adaptive scrolling backdrop

As a complete novice in HTML/CSS, I am attempting to create my portfolio. My approach is to start with the most basic elements, beginning with the background. Since my main page is a large scrollable one, I want the background to fit the screen size of the ...

putting a division element above a image carousel

Is there a way to overlay a div tag on top of a slideshow, similar to the one shown in this link? In the example provided, a div with the title "DISCOVER THE JOY OF COOKING" is positioned over a slideshow. Any tips on how I can achieve this effect? ...

I can't figure out why my navbar-brand won't budge from the left side of the screen. I've attempted using ml-5, but it's still not

https://i.sstatic.net/wo35v.jpg I have experimented with different margin classes like ml-5 in Bootstrap 5 to create spacing. <body> <nav class="navbar navbar-expand navbar-dark bg-dark"> <a class="navbar- ...

Ensuring uniform div lengths with HTML and CSS

There are 3 divs in the example below: https://i.sstatic.net/ouN6V.png <ul> <div class="parent"> <li> <div> Lorem Ipsum is simply dummy </div> </li> </div> <li> <div class="parent"> <div& ...

Is it possible to generate a triangular attachment below a div element?

My designer sent me a unique design and I'm wondering if it's possible to replicate using HTML, CSS, or JavaScript? https://i.stack.imgur.com/spB71.png I believe it can be done with CSS by creating a separate div positioned absolutely under the ...

Can you please provide the CSS code that would style this table in a similar manner?

I am interested in utilizing the design of this table, but how can I update it to meet CSS standards and HTML5 equivalents? <html> <head></head> <body> <table border="1" bordercolor="#000000" style="background-color:#ffffff" w ...

How can you align square cells within a container using CSS grids while maintaining a consistent grid gap?

Our objective is to perfectly align square cells with the edges of their container while maintaining a consistent gap between cells in each row and column. Although this Codepen solution is close, there are two key issues: (1) vertical spacing doesn' ...

Centered CSS Box with Pointing Arrow

I'm looking for a way to create a unique div design that includes an arrow pointing downwards attached to the bottom. After some exploration, I was able to achieve this look through this process: http://jsfiddle.net/hyH48/. However, my challenge lies ...

What is the best way to retrieve data from a POST request?

I am attempting to post data from the same site and create a new order when the submit button is clicked. However, I am not receiving any information in my req.body, leading me to suspect that there may be an issue with my ejs file. Any feedback on this ma ...

Issue encountered while attempting to log into a secondary webpage HTML - auto complete function malfunctioning

I am currently working on a project that involves using a sidebar HTML page as a form to update a sheet, which is a very basic operation. The main issue I am facing is with the autocomplete feature. As a beginner in coding HTML with Google Apps Script, pl ...

The presence of an iframe disrupts the order of the

I have a website () that utilizes CSS to keep the header, menu, and footer fixed while allowing the content to scroll. Recently, I added a photo page using an iframe and it seems to be working well (although some adjustments are still needed for different ...

Null values have been detected in the request.form elements

I am facing an issue with a simple asp.net webform. When I post it to another page, the request.form collection appears to be empty. I am unsure of what mistake I am making. Form: <form runat="server" id="myform" action="submitForm.aspx" method="post" ...

Ways to ensure that a jQuery function does not run until another one has finished

My JQuery functions are as follows: First Function $(function(){ $(".staffDiv div").hide(); $(".staffDiv img").hover(function(){ $(this).next(".staffDetails").slideToggle("slow").siblings(".staffDetails:visible").slideUp("fast"); $(this) ...

Creating a simulated textarea with a scrollbar and dynamically refreshing the content

Due to limitations on markup content inside <p> tags, I have decided to create my own custom textbox. This textbox will function as a console where the battle progress is logged. Initially, I attempted using nested divs for each log, but encountered ...

Unusual shift in behavior - <input> on Windows 8.1

Our application is a unique HTML5/WinJS Google Talk app tailored for Windows 8 users. Within our app, we utilize a textarea for chat input with a predefined maximum height. We have coded the height to automatically adjust to the maximum limit once reached. ...

Leverage the power of effekt in your AngularJS development

Can anyone demonstrate how to implement animation effects with AngularJS? Has someone created an example using Effeckt.css? ...

What options exist for the format field in a font-face src declaration?

How can I determine when and how to use different font formats, and are they always necessary? Various websites provide examples like the ones below, with different arrangements: @font-face { font-family: 'Example'; src: url('Example.eo ...

Bootstrap 3 offset doesn't respond to dimensions

Even though I have set an offset for a medium-sized screen, the offset still appears in large screens. Here is a snippet of my HTML code. How can I resolve this issue? <div class="col-lg-6 col-sm-12"> <div class="row"> <div class="co ...