Exciting animated effect that changes the color of the underline

After attempting to decipher the code used by the creator, I still couldn't quite grasp it.

I am eager to recreate a similar effect to the animated sliding bar in the top right corner. The way it changes color as it appears and disappears is quite mesmerizing.

I believe the foundation of this effect lies in the code from . Although I have been able to make the sliding bar change color using this code, the transition isn't as smooth and the color change feels too abrupt.

This is my attempt: http://codepen.io/Dingerzat/pen/mOmzVp

/* CSS */

.sliding-u-l-r-l {
    display: inline-block;
    text-decoration:none;
    color: #000000;
    position: relative;
    padding-bottom: 3px;
}
.sliding-u-l-r-l:before {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 0;
    transition: width 0s ease, background .5s ease;
}
.sliding-u-l-r-l:after {
    content: '';
    display: block;
    position: absolute;
    right: 0;
    bottom: 0;
    height: 3px;
    width: 0;
    background: blue;
    transition: width .5s ease;
}
.sliding-u-l-r-l:hover:before {
    width: 100%;
    background: red;
    transition: width .5s ease;
}
.sliding-u-l-r-l:hover:after {
    width: 100%;
    background: transparent;
    transition: all 0s ease;
}

.

<!-- HTML -->
    <a class=sliding-u-l-r-l href="http://codepen.io">A link that is and never is</a>

Answer №1

Are you searching for a solution like this?

HTML

<a class=sliding-u-l-r-l href="http://codepen.io">A unique link that stands out</a>

CSS

.sliding-u-l-r-l {
    display: inline-block;
    text-decoration:none;
    color: #000000;
    position: relative;
    padding-bottom: 3px;
}
.sliding-u-l-r-l:before {
    /*
      The background color is placed here to ensure visibility even after the link has been unhovered.
    */
    background: red;
    content: '';
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 0;
    transition: width 1s ease; /* Red underline's width change takes 1 second */
}
.sliding-u-l-r-l:after {
    content: '';
    display: block;
    position: absolute;
    right: 0;
    bottom: 0;
    height: 3px;
    width: 0;
    background: blue;
    transition: width 1s ease; /* Blue underline's width change duration can be customized */
    transition-delay: 1s; /* Wait until red underline's transition finishes */
    z-index: -1; /* Ensure blue underline shows underneath the red one */
}
.sliding-u-l-r-l:hover:before {
    width: 100%;
    transition: width .5s ease;
}
.sliding-u-l-r-l:hover:after {
    width: 100%;
    background: transparent;
    transition: all 0s ease;
}

Miscellaneous:

Please Note: Feel free to ask if you have any questions or need further clarification.

Addendum: Check out this example for reference.

Extra Info: The CSS code is extensively commented for better understanding. If anything seems confusing, refer to the comments in the CSS section.

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

Creating Overlapping Sections Using Bulma CSS

I'm currently diving into the world of Bulma and aiming to create a simple page layout with the following structure: <header> <hero> <section> <footer> However, I'm encountering an issue where these elements are overlapp ...

Adjusted the background scale transformation without impacting the content inside the div

My concern revolves around the transform: scale property. I am trying to achieve a gradual zoom effect on my background when hovered over, without affecting the text content. I have omitted browser prefixes for brevity. Below is the CSS code: #cont-nl { ...

jQuery's resize() function is not functioning properly

I have a question about resizing my menu items using jQuery. Currently, I am successfully able to resize the list items when the page is reduced in size. However, when I try to increase the page size, the list items do not decrease accordingly. Is there a ...

Utilizing the child element's attribute value in a list to dynamically modify the CSS styling of a div element

I'm struggling with designing a ranking bar that consists of 9 bars. I want the height of the bars to vary, with bar 0 and bar 8 being the longest. However, I am having difficulty manipulating my jQuery selector to change the CSS style of the bars bas ...

Having difficulty in getting rid of the horizontal scrollbar

I need help replacing the horizontal scrollbar with arrow buttons to scroll through images (not the entire page). This is the code I tried: .scroll-images::-webkit-scrollbar{ -webkit-appearance: none; } However, the scrollbar is still ...

An unidentified element is displayed as undefined

I am trying to implement a CSS change for mobile devices, but an unknown variable keeps showing up as undefined. Despite researching various tutorials and finding multiple solutions, I am struggling to grasp them as I am a novice in JavaScript and HTML. T ...

Can you explain how HTML and JavaScript work together in terms of execution order?

As a newcomer to JavaScript, I'm curious about the execution order of line1, line2, and line3 in my code. My initial assumption was that it would display the paragraph first (line 1), followed by the image (line 2), and then trigger a prompt. However ...

Dispense CSS using a React element

My React component index.js contains styling in style.css. I am looking to share this component on npm, but I am unsure of how to simplify the process for other developers to use the styling. After exploring different options, I have come across three ap ...

Create a border that does not inherit the opacity of the object

Check out this jsBin for reference: http://jsbin.com/uyonux/1 The hover state is working fine, but the focus state is not. I want the blue color to remain solid #13A3F7 without inheriting the opacity of .4. Is there a way to achieve this without the elem ...

Locating a File in the Bootstrap 4 File Explorer

Bootstrap 4's file browser lacks the file name display, showing only "Choose file...". To address this issue, I created a JavaScript solution. Are there any alternative methods to solve this problem? HTML <label class="file"> <input typ ...

Bootstrap 4 has an enlarged input field when compared to the select input

I am facing an issue with the size of my select field, which appears larger than my two input fields in Bootstrap 4.3. Can anyone provide guidance on how to make the select field match the size of the input fields? Your assistance would be greatly apprecia ...

Positioning the Iframe directly beneath the header

Hey there, I have this little issue that's been bugging me. In my index page, I've included the header.php, followed by an Iframe. <body> <?php include 'header.html' ?> <div class="clear"></div> ...

A webpage featuring a 2-column layout with a footer, along with a right column that is absolutely positioned and

I'm currently working on a basic two-column layout: <div class = "parent"> <div class = "left-column"> </div> <div class = "right-column"> </div> </div> <div class = "footer"></div> The con ...

Is it time to go back to the parent selector using the ampersand symbol?

I recently started using Less for writing CSS, and it has definitely been a time-saver for me. However, I have encountered a small issue with my code: <a href="#" class="btn-black-bg btn-right-skew">largest fight gym in Australia</a> Less .b ...

Generate an HTML table dynamically from a PostgreSQL query

I am facing a challenge that may be simple for experienced individuals but is proving to be difficult for me as a newbie. The task at hand involves retrieving JSON data from a database query and displaying it in an HTML table using Node.js, Express, and Po ...

Firefox is able to print multiple pages with a rowspan feature

I am facing an issue with a table that contains a large amount of data and uses related cells via row span. When I try to print using the Mozilla/ Firefox engine, the print preview shows almost 100 pages with just a single line on each page. I attempted t ...

Hover animation using CSS is a great way to add interactivity

I'm trying to create an animation in a moving box that flips upside down when the mouse is raised. I've attempted to use keyframes and hover to achieve this effect, but it's not working as expected. Any suggestions on how to make it work? ...

Tricky problem with z-index - how to position a CSS3 triangle under the menu

Hey there, thank you for taking the time to look into my issue. I'm currently working on a menu design that I would like to resemble this example: The key feature here is creating triangular shapes on either side and positioning them beneath the men ...

Guide to making a CSS rectangle with one side taller than the other

Having difficulty with CSS while attempting to design a unique shape. This is the specific shape I am aiming to achieve: view image reference here If you have any solutions or tips, please share! Thank you in advance. ...

How come the text input on my website automatically displays a "#" in the URL?

Here is the code snippet I am working with: <div class="container text-center"> <h1 class="display-3">What's the weather</h1> <p class="lead"><strong>Please enter a city name:</strong></p> ...