Ways to gradually transition gradient color when hovering?

I am trying to modify the color of a linear-gradient() smoothly upon hovering, similar to how a solid color changes. I searched on w3schools and the Mozilla network for a solution but couldn't find anything. I attempted to apply the transition property like you would for solid colors (transition: background 1s linear), but it didn't work. Any suggestions? I have included the HTML and CSS code below:

<header>
<nav class="navbar navbar-dark bg-dark" aria-label="navbar">
  <div class="container-fluid justify-content-between">
    <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#leftMainNav"
      aria-controls="leftMainNav" aria-label="Toggle left navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="index.php">
      <img src="assets/images/logo-l.png" class="img-fluid" alt="CBS Logo">
      <span class="navbar-brand-text">CherryBerry Studios</span>
    </a>
    <div class="d-flex" style="width:240px;">
      <ul class="navbar-nav">
        <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" role="button" aria-expanded="false">Company</a>

        ...
        ...

    </div>
</nav>
    .navbar-brand-text {
  background: -webkit-linear-gradient(green, magenta, red);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: background 1s;
}

.navbar-brand-text:hover {
  background: -webkit-linear-gradient(blue, red,);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

Answer №1

Transitioning a background gradient to change to another color set entirely is not possible. However, you can achieve a similar effect by setting up a linear gradient with all the colors you need and adjusting its size to 200% width. Then, on hover, you can transition the background position to 100%.

To visualise this concept, I created a quick mockup on Codepen.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Gradient Text Hover Effect</title>
  <style>
    body {
      background: #444;
    }   

    .navbar-brand-text {
      text-align: center;
      font-size: 40px;
      background: linear-gradient(to right, crimson,pink,springgreen);
      background-clip: text;
      -webkit-text-fill-color: transparent;
      background-size: 200% 100%;
      background-position: left center;
      transition: background 1s linear;
    }

    .navbar-brand-text:hover {
      background-position: 100% center;
    }
  </style>
</head>
<body>
  <div class="navbar-brand-text">Hover Me</div>
</body>
</html>

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

Align and resize image using CSS styling

Seeking assistance on centering and cropping images using CSS. Tried implementing the technique from this specific article. However, experiencing inconsistencies in device UI output. Can someone shed light on this behavior? Scenario: The objective is t ...

What is the CSS code to modify the color of an SVG ::marker?

I am looking to change the color of an SVG li::marker based on the font color. I attempted using fill="currentColor" but it did not work as expected. Any suggestions on how to resolve this? li::marker { content: url("data:image/svg+xml,% ...

How to customize the color of radio buttons in JFXRadioButton using CSS

I am facing an issue with customizing the styling of JFXRadioButton component from this library : jfoenix.com I want to modify the color of the circle, but the default class is not working. Are there any suggestions or solutions available? (The colors me ...

positioning a div based on the location of another div

I am currently working on aligning a div that sits at the bottom of all other divs. The last div is set to float and aligned at the top using CSS. I am unsure how to align it from the left side without any issues when the screen resolution changes. Is th ...

Troubleshooting Challenges with JavaScript DOM Manipulation

I am facing an issue with a table where I need the first column to remain fixed when scrolling horizontally. The code snippet below works perfectly for the first column of td's, but fails to work for the tr's. Despite checking the code thoroughly ...

Using Bootstrap 5 in conjunction with Electron is causing compatibility issues

This is my first venture into creating an electron app and I wanted to add some styling using bootstrap 5. Here's what I did: (1) I used npm i --save bootstrap jquery popper.js to install the necessary modules (2) Created a main.scss file including ...

Changing colors when hovering over different elements

I am struggling to create a hover color change effect that applies to all elements (icon, text, and button) from top to bottom. Currently, the hover effect only changes the color of either the text and icon or the button individually. Below is the code sn ...

The Angular API request is continuously retrieving data every single second

I recently inherited some Angular/ng-bootstrap code that included a table with static data, which was functioning perfectly. However, the requirement now is to fetch the data from an API call. In an attempt to modify it accordingly, I referred to an answer ...

What is the best way to create a page that moves on release using HTML/CSS?

I'm working on a website where I want to make an interactive feature. When users click on an image on the left side of the page, I want the page to move backward. Similarly, when they click on an image on the right side, I want the page to move forwar ...

CSS Techniques for Smooth Transitions

When the hamburger icon is pressed, a menu appears over the current page with CSS from Glamor. The menu slides in perfectly from the right side of the screen, but I am having trouble getting it to slide out when any part of the menu is clicked. I have def ...

What are some effective methods for overriding materialui styles?

Here is the CSS style for a checkbox in Material-UI that I captured from the console: .MuiCheckbox-colorPrimary-262.MuiCheckbox-checked-260 I attempted to override this style using the following code, but it was unsuccessful: MuiCheckBox: { colorP ...

Incorporating HTML5 audio elements in JavaScript

I am working on a project where I need to create a grid of 16 audio files with separate links for each in HTML, CSS and JavaScript. Each box in the grid should link to a different audio file. My initial thought was to use a table to achieve this, so I cre ...

Exploring Techniques for Streamlining HTML/CSS Editing in Browser

Is there a way to automatically edit specific lines on websites right after they load? Specifically, I want to change <div class="1"> to <div class="1" style="display:none">, and <div class="2" style ...

Flex-boxes are set inside a fixed-positioned div in this chat web application

I am currently working on a chat web application that has a unique bottom bar layout. The bottom bar consists of a button on the left, a text entry field in the center, and another button on the right: <div id="bottom-bar"> <div class=" ...

The persistent issue of the modal box disappearing persists, despite my efforts to remove additional instances of bootstrap.min

I have been struggling to prevent my modal box from disappearing, despite trying various solutions found online. How can I ensure that it stays visible? Here is the code in question: <html> <head> <title> Test Slides </titl ...

Switching the background image upon hover while incorporating a subtle fade transition in HTML and CSS

Is there a way to set two background images on a div and have them change when hovering with a fade effect? Similar to the example shown. .kid { max-width:50%; position:relative; } .kid img { display:block; opacity:1; height: auto; transition:.6s ease; ...

Placing a list item at the beginning of an unordered list in EJS with MongoDB and Node.js using Express

What I've done: I already have knowledge on how to add an LI to UL, but it always goes to the bottom. What I'm trying to achieve: Add an LI to the top so that when my div.todos-wrapper (which has y-oveflow: hidden) hides overflow, the todos you a ...

What are some ways to adjust the size of the option field in a select menu?

In my ionic popup, I have a HTML property called select with nested options. Below is the code snippet along with the applied CSS. My query is how can I set the white space to occupy the entire area of the select? https://i.stack.imgur.com/iPqAa.png http ...

The overlay is larger in size compared to the video positioned beneath it

I'm having trouble placing a video underneath a purple layer as the overlay isn't aligning properly with my video. https://i.sstatic.net/DCzWy.jpg After removing the background-size: cover; in the home section, it appears like this: https://i. ...

Guide to creating animated sections using only CSS as you scroll the webpage

I am searching for a method to add animation effects (using @keyframes, transform...) to certain elements as the user scrolls down the page. For instance: When the offset is 0: the div will have a height of 100px. When the offset is between 0 and 100: th ...