Reputation: 31
I searched alot about this and couldn't find , how can I make something similar to the navbar here , when you hover on it a line under it will appear like a loading bar . - example : http://www.thecrewgaming.com/ is it possible only with css or javascript is needed and how ? thanks !
I tried this
li:hover {
background-color: rgba(255, 245, 255, 0.2);
border-bottom-color: #abcdef;
}
li {
font-family: 'Poppins', sans-serif;
font-weight: bold;
color: #F5F5F5;
font-size: 0.8889em;
text-decoration: none;
font-weight: normal;
text-transform: uppercase;
border-bottom: 3px solid transparent;
padding-bottom: 0.125em;``
transition: border-bottom-color 50ms linear 0s;
}
but it appears as a normal line and not like a loading bar in the page linked above .
Upvotes: 2
Views: 6498
Reputation: 7614
It's quite simple.
You use a position:absolute;
property on a ::after
pseudo selector.
See the fiddle and the code below:
https://jsfiddle.net/cuv6bxs5/
li {
font-family: 'Poppins', sans-serif;
font-weight: bold;
color: red;
background-color: #404040;
float: left;
position: relative;
padding: 10px 20px;
overflow: hidden;
}
li::after {
background-color: red;
content: "";
width: 0;
height: 3px;
left: 0;
bottom: 0;
transition: width 0.35s ease 0s;
position: absolute;
}
li:hover::after {
width: 100%;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
<ul>
<li>ONE</li>
<li>TWO</li>
<li>THREE</li>
<li>FOUR</li>
</ul>
Upvotes: 3
Reputation: 62636
There are several ways to do this.
They did it using the :after
pseudo selector with transition
for the animation.
header .menu_links a {
display: inline-block;
font-weight: 600;
font-size: 14px;
height: 50px;
color: #fff;
text-transform: uppercase;
padding-left: 20px;
padding-right: 20px;
overflow-x: hidden;
position: relative;
transition: .25s ease all;
background: gray;
text-decoration: none;
line-height: 45px;
}
header .menu_links a:after {
content: " ";
position: absolute;
display: block;
bottom: 0;
left: -100%;
height: 5px;
width: 100%;
background: #dd0034;
transition: .5s ease all;
}
header .menu_links a:hover:after {
left: 0;
}
<header>
<div class="menu_links">
<a href="#">Link A</a>
<a href="#">Link B</a>
</div>
</header>
Upvotes: 1