Is there a way to create a hover effect in my navbar where a line appears from the bottom left and top right, without causing any size or alignment issues with the links?
* {
margin : 0;
padding: 0;
}
nav{
background-color: black;
width: 1200px;
height: 110px;
position: relative;
z-index: 10;
}
ul{
left: 0;
}
.nav{
position: relative;
}
.navlink{
margin-right: 14px;
}
.navlink1{
margin-right: 14px;
margin-left: 14px;
}
.navlink4{
margin-right: 0;
}
.navlink::before{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
float: right;
}
.navlink:hover::before{
width: 100%;
transition: width .5s;
}
.navlink::after{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
}
.navlink:hover::after{
width: 100%;
transition: width .5s;
}
.navlink1::before{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
}
li{
display: inline-block;
}
li a{
display: inline-block;
background-color: #FFDA45;
border: black solid 1px;
color: white;
text-decoration: none;
padding: 20px;
width: 235px;
margin-top: 11px;
margin-bottom: 11px;
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 200%;
}
<nav>
<ul class="nav">
<li><a class="navlink" href="index.html">Home</a></li>
<li><a class="navlink" href="TLOU part II.html">TLOU part II</a></li>
<li><a class="navlink" href="Video's.html">Video's</a></li>
<li><a class="navlink" href="Music.html">Music</a></li>
</ul>
</nav>
I initially used float: right; to make the line come from the right side but encountered unexpected behavior. Here is how it works without using float: right:
* {
margin : 0;
padding: 0;
}
nav{
background-color: black;
width: 1200px;
height: 110px;
position: relative;
z-index: 10;
}
ul{
left: 0;
}
.nav{
position: relative;
}
.navlink{
margin-right: 14px;
}
.navlink1{
margin-right: 14px;
margin-left: 14px;
}
.navlink4{
margin-right: 0;
}
.navlink::before{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
}
.navlink:hover::before{
width: 100%;
transition: width .5s;
}
.navlink::after{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
}
.navlink:hover::after{
width: 100%;
transition: width .5s;
}
.navlink1::before{
content: '';
display: block;
width: 0;
height: 5px;
background:darkred;
transition: width .5s;
}
li{
display: inline-block;
}
li a{
display: inline-block;
background-color: #FFDA45;
border: black solid 1px;
color: white;
text-decoration: none;
padding: 20px;
width: 235px;
margin-top: 11px;
margin-bottom: 11px;
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 200%;
}
<nav>
<ul class="nav">
<li><a class="navlink" href="index.html">Home</a></li>
<li><a class="navlink" href="TLOU part II.html">TLOU part II</a></li>
<li><a class="navlink" href="Video's.html">Video's</a></li>
<li><a class="navlink" href="Music.html">Music</a></li>
</ul>
</nav>
I want the hover effect to remain the same but have the top line come from the right side instead.