Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS animated underline in position absolute issue

Tags:

html

css

I have an issue with an animated underline effect I got from HERE. When I apply i to the code for elements inside and absolute div, the underline applies to the entire div, not the a tag itself.

Here's the html of the portion:

<div class="navbar">
            <div class="elem">
                <p><a href="#" class="tt">Element</a></p>
                <p><a href="#" class="m">Element</a></p>
                <p><a href="#" class="m">Element</a></p>
                <p><a href="#" class="m">Element</a></p>

            </div>
        </div>

Minimal codepen: HERE

Any help would be gladly appreciated

like image 935
aln447 Avatar asked Jun 08 '26 18:06

aln447


2 Answers

You forgot to position the anchor link since it is the 'parent' to the pseudo-element.

Codepen Demo

.navbar a {
    color: white;
    text-decoration: none;
    width: auto;
    position: relative; /* here */
}
like image 59
Paulie_D Avatar answered Jun 11 '26 11:06

Paulie_D


Just add position:relative to the paragraph element

.navbar p {
    font-size: 30px;
    display: table-cell;
    text-align: center;
    position: relative;
}

https://codepen.io/anon/pen/KVbbQe?editors=1100

like image 21
Joseph Marikle Avatar answered Jun 11 '26 11:06

Joseph Marikle