how to get my navigation button stay active

2019-08-06 14:23发布

问题:

Can't get my navigation to stay active using html and css. It just light up but does not stay active when pressed. What am I missing?

How do I make it stay active when pressed? Really need the help fast! Sorry for my bad code, I'm new to coding.

How do I type the active class? I tried to, but it did not work.

HTML

<div id="apaknavig">
  <div id="menu2">
    <ul>
      <li><a href="uznemums.html">Uzņēmums</a></li>
      <li><a href="kontakti.html">kontakti</a></li>    
    </ul>
  </div>
</div>

CSS

#apaknavig {
  Width: 200px;
  height: 604px;
  top:-613px;
  position:relative;
  font:14px Arial;
  color:black;      
  float:left;
  right:35px;
  text-indent:12px;
  display: block;
  line-height:30px;
}

#menu2 ul{
  list-style:none;
  float: left;
  font:14px Arial;
  color:black;  
  right:90px;
  text-decoration:none;
  text-align:left; width:10px;
  display: block;
  line-height:30px;
  margin-bottom:10px;
}

#menu2 a{
  background-image: url(bildes/apak_navig.png);
  display:block;
  width: 196px;
  height:34px;
  font:14px Arial;
  color:black;  
  float:left;
  right:90px;
  text-decoration:none;
  display: block;
  line-height:30px;
  margin-bottom:3px;
}

#menu2 a:hover{
  background-image: url(bildes/apak_navig_green.png);
  color:white;
  font:14px Arial;
  color:black;  
  text-decoration:none;
  display: block;
  line-height:30px;
}

回答1:

Just change #menu2 a:hover{ to #menu2 a:hover, #menu2 a:active {.

You just have to add #menu2 a:active to the CSS.

#menu2 a:hover,#menu2 a:active{
  background-image: url(bildes/apak_navig_green.png);
  color:white;
  font:14px Arial;
  color:black;  
  text-decoration:none;
  display: block;
  line-height:30px;
}

I tried it but it just does not work. It continues to just hover, but does not stay active when I press it.