What are the steps to make a unique and eye-catching text underline animation?

I'm encountering an issue while attempting to create a hover animation for an <a> tag with an underline effect, similar to the example showcased on this particular webpage. Even though the tutorial is readily available, my implementation seems to be failing without clear reasons.

Below is the snippet from my CSS file:


#about-text-box a {
    text-decoration: none;
    font-size: 17pt;
    font-family: 'Silkscreen', cursive;
    color: #ECE0E7;
    text-align: center;
    width: 95%;
    text-shadow: 2px 2px 2px #101400;
    transition: 0.5s;
}

#about-text-box a:hover::after, #about-text-box a:focus::after {
    opacity: 1;
    transform: translate3d(0, 0.2em, 0);

}

#about-text-box a::after {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0.1em;
    background-color: inherit;
    opacity: 0;
    transition: opacity 300ms, transform 300ms;;
}

Answer №1

Upon review, I have identified a few properties that are missing:

  1. The a::after pseudo-element is lacking the content: '' property. This property must be specified even if it is an empty string.
  2. To align with the positioning of the pseudoelement, position: relative should be added to the a element.
  3. The use of background-color: inherit on a::after seems unsupported as there is no apparent inheritance. A temporary value like hotpink has been applied, but this can be adjusted to fit the design requirements.
  4. To enhance the desired outcome, cursor: pointer has been included in the styling for a.

I trust these enhancements will be beneficial!

For reference, below is an example with a live demo featuring a button:

#about-text-box {
  display: flex;
}

#about-text-box a {
  display: block;
  position: relative;
  padding: 0.2em 0;
  cursor: pointer;
  text-decoration: none;
  font-size: 17pt;
  font-family: "Silkscreen", cursive;
  color: #ece0e7;
  text-align: center;
  text-shadow: 2px 2px 2px #101400;
  transition: 0.5s;
}

#about-text-box a:hover::after,
#about-text-box a:focus::after {
  opacity: 1;
  transform: translate3d(0, 0.2em, 0);
}

#about-text-box a::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0.1em;
  background-color: hotpink;
  opacity: 0;
  transition: opacity 300ms, transform 300ms;
}
<div id="about-text-box">
  <a>Hover this link</a>
</div>

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

Modifying KineticJs.Image with css styling

Hey there, I'm currently working on a project that involves canvas manipulation. I've successfully figured out how to draw an image and move it within the canvas, which wasn't too difficult to achieve. However, I'm now facing a challeng ...

Incorporating a Layered Div onto a Presentation Slider

Over at , we have a slider featured on the homepage. I am attempting to place a div ABOVE the image but BELOW the text. Essentially, my goal is to add a semi-transparent white overlay to enhance the image on the slider while keeping the text visible for b ...

Is it necessary to include extra spaces following the input?

My HTML code looks like this: <label> <input type="checkbox"> Print document </label> One issue I am facing is that the "Print document" text is always stuck to the checkbox. I am unable to add "Print Document" in a new element or contr ...

Arrange two divs side by side

Is there a way to align the two divs below side by side? <div style="display:inline;float:left;"> <img src="Imagens/myimg.png" /> </div>'; <div style="display:inline;float:left;"> <img src="Imagens/myimg2.png" /> ...

Having trouble with elFinder? Encountering an error stating "Undefined is not a function" when attempting to

I am currently in the process of integrating the elFinder file manager into my project. Here is a summary of what I have accomplished so far. I have included the following files: $arr_css = array( "main.css", "jquery-ui.cs ...

Attempting to align two text boxes in the center using the text-align property

I've been attempting to center two text boxes using text-align. Unfortunately, they didn't align properly, as evident in this snapshot: https://gyazo.com/c47f4037ba1ab3abef5833358d94172e. What could have caused this misalignment, and how can it b ...

obtaining extra space in the final portion of a table cell

I've been attempting to place the image and text next to each other, but I couldn't figure out how to make the image adjust its size (height & width) to fit into the table cell. Additionally, there seems to be extra space and the background color ...

What is the best way to position a banner image behind the navigation bar on my website?

I'm struggling to position the banner image behind the navigation bar on my website. It keeps appearing below the navigation bar, but I want it to be positioned behind the navigation bar instead. Here is the code I'm using: * { margin: 0; ...

methods for adjusting the transparency of the background image while keeping the foreground image visible

I am using Twitter Bootstrap to create a carousel on my website. Currently, I have set the foreground image as the current image and the background image as the next one. However, I want to adjust the opacity of just the background image. Can someone pleas ...

"Troubleshooting a CSS Bug on a PHP Dynamic Web

I have a PHP web page that is dynamic. localhost/ctd/index.php Everything is working fine, except when I add a forward slash like this: localhost/ctd/index.php/ The CSS does not load. Is this a CSS bug or PHP issue? Here is the full code of index.php: ...

JQuery is throwing an unhandled reference error

I'm currently working on a jQuery script that looks like this: <script type="text/javascript"> $(document).ready(function () { var $containerHeight = $('.container').height(); if ($containerHeight < 760) { ...

html5 Showing and hiding div elements

Here is a snippet of code to consider: @using App.Models @model App.Models.AllPeopleViewModel @{ ViewBag.Title = "Index"; } <html> <head> </head> <body> @foreach (Customer person in Model.Content) { <div class=&qu ...

The Bootstrap navigation bar is experiencing issues and is not functioning properly, as the classes are not

<nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" d ...

Themed CSS for Header in HTML Tables

Looking to add some creative CSS theming to the header of a table? Unfortunately, tables don't support this natively. But fear not – there's a workaround! My solution is to insert an element BEHIND the table head and apply the desired styles t ...

What is the reason behind using '-webkit-backface-visibility: hidden;' to resolve problems with negative margin transitions on iOS/iPad 5.1?

During the process of resolving my issue, I accidentally discovered a solution - but I always prefer to understand the fixes I apply. <ul> <li><img src="something.jpg" /></li> <li><img src="somethingElse.jpg" />< ...

Despite being correctly linked in EJS and without any errors, the CSS is still not loading

Hey there, I'm facing an issue with linking a CSS file to an EJS file. I believe that I am connecting them correctly: <head> <title>Acres & Karats Calculator</title> <base href="/"> <link type="text/css" href="css/Acres ...

Expanding list item with jQuery

I am facing an issue with the dropdown functionality of my <li> elements. The problem occurs when clicking on the 4th option, as the expander appears on top instead of dropping down beneath the list item. If you check out this jsFiddle, you can see ...

How come ng-class doesn't apply to a specific class name?

I recently wrote the following code: <style> .dotted { border:dotted; } </style> .... <p ng-style="mystyle" ng-class="dotted">{{ answer }}</p> My intention was to have the paragraph element enclosed within a ...

I'm having trouble keeping items aligned on my navigation bar right after a form. Can anyone help me with this?

I'm having trouble fitting a navbar with these elements: My brand logo A lengthy search bar and submit button filling the entire height of the navbar. Space at the end of #2 for another button of equal height. ... all in one line without collapsing ...

The image spills out of its confines

Looking to create a dialogue box that fills the entire width and height of the screen? Want to divide its content into two sections - an image and a footer area with 2 rows of height? Struggling to contain the image within its designated space without over ...