I'm currently utilizing React js and have developed a navigation bar that showcases animated lines expanding from 0% to 100% under each item on hover. Additionally, the last clicked item is assigned the .current
class. However, I encountered an issue where adding CSS to move the text inside the <li>
elements on hover caused this functionality to break.
Snippet:
html,
body {
padding: 0;
margin: 0;
font-family: "sequel-sans-roman", -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
.container {
padding: 0 2rem;
}
.main {
min-height: 100vh;
padding: 4rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}
.navIcon {
display: inline-block;
flex-grow: 1;
}
.nav {
display: flex;
justify-content: space-between;
width: 100%;
margin-top: 2.4em;
/* coordinates w height of line away from link, MUST BE = */
}
.snip1168 {
text-align: center;
text-transform: uppercase;
}
.snip1168 * {
box-sizing: border-box;
}
.snip1168 li {
display: inline-block;
list-style: outside none none;
margin: 0 1.5em;
padding: 0;
background: ppink;
}
.snip1168 li {
padding: 2.4em 0 0.5em;
/* height of line away from link */
color: rgba(0, 0, 0, 1);
position: relative;
text-decoration: none;
background: pink;
display: inline-block;
}
.snip1168 li:before,
.snip1168 li:after {
position: absolute;
-webkit-transition: all 0.35s ease;
transition: all 0.35s ease;
}
.snip1168 li:before {
top: 0;
display: inline-block;
height: 3px;
width: 0%;
content: "";
background-color: black;
}
.snip1168 li:hover:before,
.snip1168 .current a:before {
opacity: 1;
width: 100%;
}
.snip1168 li:hover:after,
.snip1168 .current li:after {
max-width: 100%;
}
.mainText {
text-transform: uppercase;
font-size: 1.1rem;
}
.snip1168 li a {
transition: transform ease 400ms;
transform: translate(0, 0);
display: inline-block;
}
.snip1168 li:hover a {
transition: transform ease 400ms;
transform: translate(0, -10px);
}
<div class='container'>
<main class='main'>
<div class='nav'>
<div class='navIcon'>
<img src="https://picsum.photos/40" height={40} width={40} />
</div>
<ul class='snip1168'>
<li class='current'><a href="#" data-hover="Work">Work</a></li>
<li><a href="#" data-hover="Recs">Recs</a></li>
<li><a href="#" data-hover="Say Hi">Say Hi</a></li>
</ul>
</div>
</main>
</div>
I attempted the following code snippet, but it did not produce the desired effect:
.snip1168 .current a {
width: 100%;
}
What is the solution to maintaining the lines at 100% width for the items with the .current
class?