.navbar-nav .dropdown-toggle::after {
display: inline-block;
margin-left: 0.255em;
vertical-align: 0.255em;
content: "";
border-top: 0.3em solid;
border-right: 0.3em solid transparent;
border-bottom: 0;
border-left: 0.3em solid transparent;
/* Custom SVG chevron for the dropdown toggle */
}
/* Custom styles for the expanding underline effect */
.navbar-nav .nav-link {
position: relative; /* Establishing a positioning context for the pseudo-element */
font-weight: bold; /* Making the text bold */
padding: 0.5rem 1rem; /* Adding padding to the navigation links */
}
.navbar-nav .nav-link::before {
content: ""; /* Creating a pseudo-element for the underline */
position: absolute; /* Absolutely positioning the underline */
bottom: 0; /* Positioning the underline at the bottom of the link */
left: 0; /* Positioning the underline starting from the left */
width: 100%; /* Making the underline span the full width of the link */
height: 3px; /* Setting the thickness of the underline */
background: linear-gradient(
to right,
blue,
red,
blue
); /* Applying a gradient background to the underline */
transform: scaleX(0); /* Initially hiding the underline with no width */
transform-origin: left; /* Setting the transform origin to the left */
transition: transform 0.3s ease; /* Adding a transition for smooth animation */
}
.navbar-nav .nav-link:hover::before {
transform: scaleX(1); /* Expanding the underline to full width on hover */
}
Thank you for sharing this excellent navbar underline ! However, upon implementation, I am encountering an issue where the dropdown is not working. Could you please advise me on how to fix this problem ?
I am not sure why it is not working for you. I brought the html and css into CodePen and it works there. My guess is you may not have copied the entire code.
You know I am not the skilled. I just kept playing around with various features I saw throughout the web. Step by step took a half a day.
I did removed much of the CSS this morning, as suggested by @PeteSharp, and it still works. I am not a coder, so I don’t know why it still works.
.navbar-nav .dropdown-toggle::after {
display: inline-block;
margin-left: 0.255em;
vertical-align: 0.255em;
content: "";
border-top: 0.3em solid;
border-right: 0.3em solid transparent;
border-bottom: 0;
border-left: 0.3em solid transparent;
/* Custom SVG chevron for the dropdown toggle */
}
/* Custom styles for the expanding underline effect */
.navbar-nav .nav-link {
position: relative; /* Establishing a positioning context for the pseudo-element */
font-weight: bold; /* Making the text bold */
padding: 0.5rem 1rem; /* Adding padding to the navigation links */
}
.navbar-nav .nav-link::before {
content: ""; /* Creating a pseudo-element for the underline */
position: absolute; /* Absolutely positioning the underline */
bottom: 0; /* Positioning the underline at the bottom of the link */
left: 0; /* Positioning the underline starting from the left */
width: 100%; /* Making the underline span the full width of the link */
height: 3px; /* Setting the thickness of the underline */
background: linear-gradient(
to right,
blue,
red,
blue
); /* Applying a gradient background to the underline */
transform: scaleX(0); /* Initially hiding the underline with no width */
transform-origin: left; /* Setting the transform origin to the left */
transition: transform 0.3s ease; /* Adding a transition for smooth animation */
}
.navbar-nav .nav-link:hover::before {
transform: scaleX(1); /* Expanding the underline to full width on hover */
}
Yes you have a double up of css. And css in the html markup.
I would suggest not learning with such large chunks. You won’t be able to follow what’s happening.
Small steps and shapes and colours.
Unless your goal is to be confused? but if that’s the case you won’t be able to show @Jerry a step by step guide of what you did, why you did it and how to tweak it.