Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep active menu item underlined?

Tags:

html

css

I'm really new to HTML and CSS. I have a navbar which underlines the menu item you hover with a fade in, fade out-effect from the middle, but how can I keep an active menu item underlined with the same style?

I'm also using Typo3 / Fluid which creates me the html code and assigns the "active" class to the active menu item.

This is how it looks like so far: https://jsfiddle.net/wr5w09r0/

css

div#top_nav{
    text-align: center;
}

div#top_nav li{
    display: inline;
    padding: 15px;
}

div#top_nav a {

display: inline-block;
position: relative;

}

div#top_nav a:hover{
    color: orange;
}


div#top_nav a:before{

  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  bottom: -3px;
  left: 0;
  background-color: orange;
  visibility: hidden;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transition: all 0.15s ease-in-out 0s;
  transition: all 0.15s ease-in-out 0s;

}

div#top_nav a:hover:before {
  visibility: visible;
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
}

.active {
    color: orange;
}

1 Answers

Hope this will help you. I have added this simple element.

div#top_nav a:hover:before , div#top_nav a.active:before

a {
  text-decoration: none;
}

div#top_nav{
	text-align: center;
}

div#top_nav li{
	display: inline;
	padding: 15px;
}



div#top_nav a {

display: inline-block;
position: relative;

}

div#top_nav a:hover{
	color: orange;
}


div#top_nav a:before{

  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  bottom: -3px;
  left: 0;
  background-color: orange;
  visibility: hidden;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transition: all 0.15s ease-in-out 0s;
  transition: all 0.15s ease-in-out 0s;

}

div#top_nav a:hover:before , div#top_nav a.active:before {
  visibility: visible;
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
}

.active {
	color: orange;
}
<div id="top_nav">
<ul>
<li class="mainMenu-itemLevel1">
<a href="index.php?id=2" class="active">seite1</a></li>
<li class="mainMenu-itemLevel1">
<a href="index.php?id=3">seite2</a>
</li><li class="mainMenu-itemLevel1">
<a href="index.php?id=4">seite3</a></li>
<li class="mainMenu-itemLevel1">
<a href="index.php?id=6">seite4</a></li>
<li class="mainMenu-itemLevel1">
<a href="index.php?id=7">Seite5 lang Hover</a></li>
</ul>


</div>

Hope this will help you.

like image 162
xaid Avatar answered Mar 18 '26 18:03

xaid