Hover over two different colors using CSS

In the menu, the default background-color of the items is white. When you hover over them, the color changes to blue.

Now, my question is -

If we keep the mouse hovering on a menu item, is it possible to first show the blue color and then after 1 or 2 seconds change to another color like yellow using CSS Transitions or any other CSS solution?

Answer №1

Give this a try for possible help

HTML code snippet:

<div class="test"><div></div></div>​​​​​​​​​​​​​​​​

CSS code snippet:

​.test{
    width:100px;
    height:100px;
    background-color:#0ff;  
   -webkit-transition:background-color 1s ease-in; 
    -moz-transition:background-color 1s ease-in; 
    -o-transition:background-color 1s ease-in; 
    transition:background-color 1s ease-in; 
}
.test div{
    width:100px;
    height:100px;
    -webkit-transition:background-color 3s ease-in;
     -moz-transition:background-color 3s ease-in;
     -o-transition:background-color 3s ease-in;
     transition:background-color 3s ease-in;
}
.test:hover{
   background-color:#f00;
}

.test div:hover{
   background-color:green;
}

Code example available on jsFiddle

Answer №2

To create an engaging visual effect on your website, consider utilizing CSS3 animations in modern web browsers. An example of this is changing the color of a button from grey to blue and then yellow for added flair.

Check out this demonstration for more insight - jsFiddle

HTML

<div class="button"></div>

CSS

.button {
    width: 150px;
    height: 50px;
    background-color: #e3e3e3;
    border: 1px solid #000000;
}

.button:hover {
     -webkit-animation: color 1.0s forwards;
        -moz-animation: color 1.0s forwards;
          -o-animation: color 1.0s forwards;
}

@-webkit-keyframes color {
      0%   { background-color: #0000ff; }
      50%  { background-color: #0000ff; }
      100% { background-color: #ffff00; }
}

@-moz-keyframes color {
      0%   { background-color: #0000ff; }
      50%  { background-color: #0000ff; }
      100% { background-color: #ffff00; }
}

@-o-keyframes color {
      0%   { background-color: #0000ff; }
      50%  { background-color: #0000ff; }
      100% { background-color: #ffff00; }
}

Answer №3

It seems like this could be the solution you've been searching for.

I'm not sure why you're in need of this particular link, as it may give off an amateurish vibe to your website due to its distracting nature. There are plenty of more sophisticated animations and plugins available, especially if you make use of jQuery. Take a look at this site for some ideas:

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

Change the toolbar's background color to a solid white, with no gradiation

CKEDITOR.replace( 'editor_1', { toolbar: [ { ..... }, ], uiColor: 'white', }); Unfortunately, the above code does not yield the desired outcome. .cke_top{background-color: white;} It appears that the specified CSS ...

CSS Priority - determining the ultimate winner

I have an upcoming exam and I'm reviewing the previous exam paper that was given to me. The question is: When multiple style sheet rules are applied to the same element, which type of rule takes precedence? a. Any declaration from the browser b. ...

Tips for implementing styling in a material table within a reactjs application

Is there a different way to set the display property to inline-block since cellStyle doesn't seem to recognize it? How can I adjust the width of a specific column, let's say with the name title, without affecting the width of all other co ...

What is the best way to split a semicircular border radius in two equal parts?

Is there a way to halve the yellow line or remove it from above the red box, while keeping it below? Can this be achieved using just HTML and CSS, or is JavaScript necessary? * { margin: 0; padding: 0; box-sizing: border-box; } body { height: 1 ...

Incorporating a static background image slideshow in ASP.NET - a step-by-step guide

I am currently working on my asp.net website and I would like to incorporate an image slideshow as the background of my homepage. This idea was inspired by a site I came across, . I have successfully implemented the slideshow, but now I am wondering if it ...

Apply the active class to only one element at a time

Presented here is a table showcasing available dates and times. Users can select a specific time by clicking on the "Choose" link. Currently, when a user selects a time, the class "active" is applied. However, the desired behavior is to remove the previous ...

Trouble with applying CSS class to checkboxlist

I am trying to display a border around each checkbox item in a checkboxlist. I believe that it can be achieved by setting the td cssclass as the checkboxlist saves items in td. However, the code I tried below is not working. Here is the ASPX code: < ...

Ways to stop Ajax long-poll from refreshing div on Chrome?

Update: Upon further investigation, I believe I am getting closer to a solution, but I still require assistance. It seems that my PHP script is returning empty responses when it queries the MySQL database and finds nothing. Instead of holding the request o ...

Troubleshooting CSS and HTML Spacing Challenges

Greetings! I am currently working on implementing a menu bar on the left-hand side of my webpage. However, I've encountered an issue where the menu bar is causing all the HTML content below it to be misaligned. Additionally, the menu bar appears visi ...

Navigating on Blogger can be a tricky task when it comes to searching and

I recently added a Table to my blogger post, along with an input form for readers to easily search data. After finding the code on W3Schools (link here), I implemented it successfully. However, I am looking to make some improvements. Here is my question: ...

Combining CSS, jQuery, and HTML into a single .html file would allow for seamless integration

I've been searching extensively, but I haven't been able to locate exactly what I need. My goal is to merge my jQuery and CSS into a single .html file, but I'm struggling to get the jQuery functionality to work. Although I have experience wi ...

What are the steps to prevent scrolling in a Flutter web app that is embedded?

This is my first question on this platform, so I hope for some gentle feedback. I am currently working on a basic flutter web application that I want to embed in an existing webpage. The app is hosted on firebase, and I have used an iFrame on the parent p ...

The React-bootstrap Modal encounters issues when handling image content and scaling for mobile display compatibility

Can someone please assist me with displaying the full image of a small image located in the gallery? Whenever I try to scale the display, the Modal automatically resizes but the image does not resize accordingly. The image ends up overlapping when scaling ...

Storing data in the browser's local storage using jQuery without requiring any CSS

I have a form that receives data and I am trying to save the first two pages of received data into localStorage: <form id="myForm" method="post"> Font Size (px): <input id="fontsize" type="text" name="fontsize" /> </form> <s ...

What adjustments can be made to the Bootstrap code to prevent it from causing layout issues with the Signin Form and Footer?

Recently, I've encountered some challenges with the footer formatting on my website's home page and the sign-in form on a separate page. It appears that the Bootstrap framework at the top of the page is affecting these elements exclusively. How c ...

Utilizing CSS to adjust the position of a background image at its starting point

I'm looking to create a unique design for the sidebar on my Tumblr page, where the header has a curved shape while the rest of the sidebar has a squared-off look with 100% height. This design should flow seamlessly off the page without a visible foote ...

What is the best way to handle media queries when determining the validity of both statements?

I'm trying to figure out how to apply CSS based on whether one of two statements is true. For instance: @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) OR and (max-device-width : 1024 ...

Adjust the product percentage discount color in WooCommerce

I am struggling to switch the box color of the percentage discount for each product from green to red. I tried modifying the function I found on Reddit, but I couldn't get it right and it caused a fatal error, crashing the entire website. Here is the ...

Establish a primary background color for the React application, with the majority of the display content

I have been working on styling a React project where App.js mainly handles routing and navigation to its components: App.js import {useState, useEffect} from 'react'; import Models from './pages/Models'; import Loadingpage from ' ...

Personalized design created using v-for

I have an array being passed through v-for and I want to use the values within the "style" attribute. Essentially, I need to append the value from v-for to style:"left"+EachValue+"px", but I'm having trouble with the syntax. I'm unsure if this ap ...