Replicating Kevin's Pen With A Different Layout
I am trying to visually replicate
https://codepen.io/kevinpowell/pen/GrLKNo
by doing
https://codepen.io/imdiau/pen/OJYQpNw
My reasoning is to increase the width of a span with colored background as I hover on the navbar item. However, as I hover, the width does not increase currently. What am I missing?
Kevin
CodePen
Navbar with fun hover effect
When you hover over a link, a bar grows out above the link, and shrinks away when you move off the link. I created this for a YouTube tutorial...
5 Replies
Right now, your
span
has a position: static
. That's the default value, and it also means that the positioning properties (top, right, bottom, left) don't do anything.
Also, because the span is an inline element, height
doesn't work either.you could do something like this without the use of other elements
thanks for the comments 🙂 I have seen this & and % syntax before, but couldn't find info on it. What does that do? I will retry with using border top, totally forgot that exists...
ah, it's a (new) way to nest selectors
this is the same as
the & sign combines (pseudo)selectors
you can read more about it here:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting
MDN Web Docs
Using CSS nesting - CSS: Cascading Style Sheets | MDN
The CSS nesting module allows you to write your stylesheets so that they are easier to read, more modular, and more maintainable. As you are not constantly repeating selectors, the file size can also be reduced.
many thanks!