CSS Transition will not be effective when applied to the background styling

I'm facing an odd yet simple issue. I have a div with the class navbaritem, and for some reason, the transition rule is being applied to the margin but not to the background.

Below is the HTML and CSS code snippet:

* {
    font-family: Raleway, Century Gothic;
}

body {
    margin: 0px;
}

a {
    text-decoration: none;
    color: #fff;
}

header > ul > li {
    margin-bottom: 5vh;
}

.navbaritem {
    position: absolute;
    width: 30vw;
    height: 6vh;
    margin-left: -8vw;
    -webkit-transform: skew(-30deg);
    -moz-transform: skew(-30deg);
    -o-transform: skew(-30deg);

    background: rgb(245, 246, 246);
    background: -moz-linear-gradient(top, rgba(245, 246, 246, 1) 0%, rgba(219, 220, 226, 1) 21%, rgba(184, 186, 198, 1) 49%, rgba(221, 223, 227, 1) 80%, rgba(245, 246, 246, 1) 100%);
    background: -webkit-linear-gradient(top, rgba(245, 246, 246, 1) 0%, rgba(219, 220, 226, 1) 21%, rgba(184, 186, 198, 1) 49%, rgba(221, 223, 227, 1) 80%, rgba(245, 246, 246, 1) 100%);
    background: linear-gradient(to bottom, rgba(245, 246, 246, 1) 0%, rgba(219, 220, 226, 
    1) 21%, rgba(184, 186, 198, 1) 49%, rgba(221, 223, 227, 1) 80%, rgba(245, 246, 246, 1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f6f6', endColorstr='#f5f6f6', GradientType=0);

    transition: 0.4s ease;
}

.navbaritem:hover {
    margin-left: -3vw;
    transition: 0.4s ease;
}

.navbaritem > a {
    height: 80%;
    margin-top: 1%;
    margin-left: -10%;
    width: 90%;
    background: url(../img/graystripes.jpg);
    box-shadow: inset 3vh 1vh 3vh #000;
    -webkit-transform: skew(30 deg);
    -moz-transform: skew(30 deg);
    -o-transform: skew(30 deg);
    position: absolute;
    text-align: center;
    font-size: 4 vh;
}

.navbaritem:hover {
    transition: 0.4s ease;

    background: rgb(255, 0, 0);
    background: -moz-linear-gradient(top, rgba(255, 0, 0, 1) 0%, rgba(247, 0, 0, 1) 21%, rgba(137, 0, 0, 1) 49%, rgba(247, 0, 0, 1) 80%, rgba(255, 0, 0, 1) 100%);
    background: -webkit-linear-gradient(top, rgba(255, 0, 0, 1) 0%, rgba(247, 0, 0, 1) 21%, rgba(137, 0, 0, 1) 49%, rgba(247, 0, 0, 1) 80%, rgba(255, 0, 0, 1) 100%);
    background: linear-gradient(to bottom, rgba(255, 0, 0, 1) 0%, rgba(247, 0, 0, 1) 21%, rgba(137, 0, 0, 1) 49%, rgba(247, 0, 0, 1) 80%, rgba(255, 0, 0, 1) 100%);
    filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ff0000', 
endColorstr='#ff0000', GradientType=0);
}

.navbaritem > i {
    font-size: 5 vh;
    color: #444;
    margin-top: 1%;
    margin-left: 85%;

-webkit-transform: skew(30 deg);
    -moz-transform: skew(30 deg);
    -o-transform: skew(30 deg);
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link type="text/css" rel="stylesheet" href="css/style.css">
        <link type="text/css" rel="stylesheet" href="css/hover.css">
        <link type="text/css" rel="stylesheet" href="css/font-awesome.css">
        <link type="text/css" rel="stylesheet" href="css/font-awesome.min.css">
        <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900">

        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/jquery-migrate-1.2.1.min.js"></script>
        <script src="js/classie.js"></script>
    </head>
    <body>
        <header>
            <ul>
                <li>
                    <div class="navbaritem">
                        <a href="#">Home</a>
                        <i class="fa fa-home"></i>
                    </div>
                </li>
                <li>
                    <div class="navbaritem">
                        <a href="#">Services</a>
                        <i class="fa fa-code"></i>
                    </div>
                </li>
                <li>
                    <div class="navbaritem">
                        <a href="#">Pricing</a>
                        <i class="fa fa-money"></i>
                    </div>
                </li>
                <li>
                    <div class="navbaritem">
                        <a href="#">References</a>
                        <i class="fa fa-flag"></i>
                    </div>
                </li>
            </ul>

            <!--<div class="navbaritem">
                <a href="#">Home</a>
                <i class="fa fa-home"></i>
            </div>-->
        </header>

        <main>

        </main>

        <footer>

        </footer>
    </body>
</html>

Answer №1

In my opinion, transitioning gradients can be a bit tricky. One way to achieve it is by using 2 elements positioned exactly on top of each other and applying your different gradients separately. Set the opacity of one element to 1 (the one with the default gradient) and then fade the opacity of that element to 0 while fading the other element to 1 when hovered. Keep in mind, this approach may not be ideal.

UPDATE I came across a workaround that might be helpful: How to use CSS3 transitions with gradient backgrounds

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

Utilize Chrome Extension to Add or Remove HTML Elements

In the process of developing a Chrome extension, I encountered a specific web page where there is a table with commented out information. I am seeking a way to eliminate the comment syntax in order to display the hidden information within the table. What ...

PHP Loop creating additional space in recurring section

I'm facing a perplexing issue that I can't seem to figure out. When I use the code provided below, it creates an extra blank row on my webpage. Interestingly, this code works perfectly fine on other pages without any issues. Although I have set t ...

Enhance Your Website with HTML and JavaScript

Here is the code snippet I am working with: sTAT **javascript** var acc = document.getElementsByClassName("item-wrapper"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function(){ this.classList.toggle("selected"); this.nextElementS ...

Ways to align the navigation icon to the left side

I need help positioning my help icon at the bottom of the screen, regardless of the user's monitor size. I've tried using margin and margin-top, but it doesn't adjust properly when changing monitor sizes. Any suggestions or assistance would ...

What causes the entire set of dynamically created cards to collapse when using the toggle collapse button in ngb-bootstrap's Collapse control?

I am currently implementing the ngb-bootstrap collapse feature in my Angular 9 application. Incorporating the ngb-bootstrap collapse functionality within a Bootstrap card, I have multiple cards being generated. Each card is equipped with a collapse button ...

Ways to correct the issue of multiple <div>s overlapping each other after being rotated by 90 degrees

Can someone assist me with rotating multiple divs without them overlapping? Below is a simplified version of my code: <div> <div class="rect"></div> <div class="rect"></div> <div class="rect"></div> & ...

Implementing interactive data changes using Vue's click event handling feature

<td> //click button required here <v-btn icon v-for="bank in order.banks" :key="bank.bankIndex">{{bank.tittle}}</v-btn> </td> <td> //display only clicked bank's price here <div v-for="ban ...

`My GitHub webpage is having trouble displaying images online`

I am experiencing difficulty with GitHub loading the images in my images folder. Strangely, it loads the background image without any issues, and when I launch the page offline, all the images load perfectly. I have checked that the images only start with ...

Employing delegate for switching roles between classes

I'm having trouble using the jQuery delegate function to toggle classes. What I want to achieve is toggling the class of <li class="unselected-values"> to <li class="<li class="unselected-values"> when the client clicks on the label ...

Having difficulty with utilizing the validate() function in jQuery

My HTML code looks like this: <form class="form-filter" id="form-filter-excel" role="form"> <div class="row"> <div class="col-md-4 col-sm-5"> <label>Date range</label> ...

Utilize selenium to retrieve data from the internet

Being a research analyst, my task involves collating data and conducting analysis. To gather the required data, I need information from this page. Specifically, I am looking for data on Abrasives to Vanspati Oils (located on the left side of the page). In ...

The issue with grunt-contrib-compass not functioning properly within npm

I recently installed npm and grunt, followed by installing grunt-contrib-compass. However, when I try to run grunt, I encounter the following error: Running “compass:dist” (compass) task Warning: not found: compass Use –force to continue. Aborted du ...

How can you animate a MUI v4 Grid element using CSS transitions?

I was exploring the potential of using breakpoints in the MUI v4 component to control the visibility of items in my Grid System. How can I create a smooth CSS transition for b, transitioning from 0px to a defined breakpoint size of 3 for xl? Using % works ...

CasperJs was unable to locate the CSS selector after transitioning from jade to pug, causing the test to fail

After transitioning my templates from jade to pug, all of my CasperJS tests started failing. The majority of the errors are related to the css selectors that cannot be found. Below is an example of the issue: CasperJS test: casper.thenOpen("http://local ...

Navigate through AJAX Live search using arrow keys and mouse controls

I have encountered an issue with the autocomplete feature on my webpage. Although I am able to input suggestions, I am unable to navigate through them using the mouse pointer initially. Oddly enough, if I press the up/down keys once after the list items ar ...

Simple steps to manipulate HTML content within a span element using JavaScript

I'm currently working on an online bus seat booking system and I've hit a roadblock with one feature. When a user selects more than one bus seat, the corresponding seat numbers should be displayed in a span or div, separated by commas. If the use ...

Obtain CONTENT from a separate CONTENT using JSExecutor

Having trouble selecting and clicking an element on a page due to the #document tag. Here is my latest attempt: var doc = (OpenQA.Selenium.Remote.RemoteWebElement)_driver.ExecuteQuery("return window.document"); doc.FindElementByXPath("//span ...

Ensure that the user's browser cache is cleared after deploying a new version on Firebase hosting

Utilizing create-react-app for my front end scripts and firebase hosting for deployment has been smooth overall. However, I've encountered an issue where updates to CSS and HTML files don't always reflect on the domain until I manually clear the ...

If the data attribute of the div ID is equal to 1 in jQuery, then

Using a jQuery plugin, I have created some "3-D stack divs". Each div has its own unique id, and the active div is marked with data-position="1", while inactive divs are marked with data-position="2" or data-position="3". Now, how can I create an if-else ...

Swapping out images by clicking on a thumbnail, featuring numerous occurrences on a single webpage

I'm currently working on a project where I need to display several large images with corresponding thumbnails. When a user clicks on a thumbnail, I want the larger version of that thumbnail to replace the current large image. While I have successfull ...