KevT
KevT

Reputation: 43

CSS Menu Disappears after Hover

I am learning css and I have created a vertical menu, hovering the mouse over the first menu item shows the sub-menu across. But my problem is, as soon as I move the mouse to the sub-menu, it disappears. How can I make it so it stays there until I clicked one of the sub-menu items? Please help.

Already searched through a lot of examples but none similar to this. I'm new to css and I'm not sure if my approach is the correct for this menu setup requirement. Please enlighten.

@charset "utf-8";

.navLeft {
	width: 25%;
	margin-top: 0%;
	top: auto;
	display: inline;
	list-style-type: none;
	margin-left: 5%;
	position: relative;
	z-index: 0;
	/* [disabled]clear: none; */
}

.navLeft ul li {
	list-style-type: none;
	width: 6em;
	height: 2em;
	/* [disabled]list-style-position: inside; */
	color: #F14E23;
	text-align: center;
	background-color: #FFFFFF;
	border: 0.5em solid #000000;
	margin-bottom: -0.5em;
	font-family: alfa-slab-one;
	font-style: normal;
	font-weight: 400;
	padding-top: 2em;
	top: auto;
	vertical-align: middle;
	padding-bottom: 2em;
	-webkit-transition: all 0.1s linear 0s;
	-o-transition: all 0.1s linear 0s;
	transition: all 0.1s linear 0s;
	position: relative;
	margin-left: -0.5em;
}

.navLeft ul li:hover {
	background-color: #F14E23;
	color: #FFFFFF;
	list-style-type: none;
	position: relative;
}
.navLeft ul .about {
	float: left;
	-webkit-transition: all .1s linear 0s;
	-o-transition: all .1s linear 0s;
	transition: all .1s linear 0s;
}
.navLeft ul ul li
 {
	float: left;
}
.navLeft ul .projects {
	clear: left;
}

.navLeft ul ul {
	display: none;
}

.navLeft ul .about:hover ~ ul{
	display: block;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>STORY</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">

</head>

<body>

<section class="mainMid">
<nav class="navLeft">
    <ul>
      <li class="about">ABOUT</li>
      <ul>
          <li class="navBeginning">BEGINNING</li>
          <li class="navMnv">Mission<br>
                  <br>
                  Vision</li>
          <li class="navPeople">People</li>
      </ul>
      <li class="projects">PROJECTS</li>
      <li class="getinvolved">GET<br>
          INVOLVED</li>
      <li class="records">RECORDS</li>
      <li class="donate">DONATE</li>
    </ul>
      
      
  </nav>

</section>

</body>

</html>

Upvotes: 4

Views: 321

Answers (1)

Ajay Narain Mathur
Ajay Narain Mathur

Reputation: 5466

Refer this fiddle : http://jsfiddle.net/zt8ffu11/

html:

<section class="mainMid">
<nav class="navLeft">
    <ul>
      <li class="about">ABOUT
      <ul>
          <li class="navBeginning">BEGINNING</li>
          <li class="navMnv">Mission<br>
                  <br>
                  Vision</li>
          <li class="navPeople">People</li>
      </ul>
        </li>      
      <li class="projects">PROJECTS</li>
      <li class="getinvolved">GET<br>
          INVOLVED</li>
      <li class="records">RECORDS</li>
      <li class="donate">DONATE</li>
    </ul>


  </nav>

</section>

css: .navLeft { width: 25%; margin-top: 0%; top: auto; display: inline; list-style-type: none; margin-left: 5%; position: relative; z-index: 0; /* [disabled]clear: none; */ }

.navLeft ul li {
    list-style-type: none;
    width: 6em;
    height: 2em;
    /* [disabled]list-style-position: inside; */
    color: #F14E23;
    text-align: center;
    background-color: #FFFFFF;
    border: 0.5em solid #000000;
    margin-bottom: -0.5em;
    font-family: alfa-slab-one;
    font-style: normal;
    font-weight: 400;
    padding-top: 2em;
    top: auto;
    vertical-align: middle;
    padding-bottom: 2em;
    -webkit-transition: all 0.1s linear 0s;
    -o-transition: all 0.1s linear 0s;
    transition: all 0.1s linear 0s;
    position: relative;
    margin-left: -0.5em;
}

.navLeft ul li:hover {
    background-color: #F14E23;
    color: #FFFFFF;
    list-style-type: none;
    position: relative;
}
.navLeft ul .about {
    float: left;
    -webkit-transition: all .1s linear 0s;
    -o-transition: all .1s linear 0s;
    transition: all .1s linear 0s;
}
.navLeft ul ul li
 {
    float: left;
}
.navLeft ul .projects {
    clear: left;
}

.navLeft ul ul {
    display: none;
}

.navLeft ul .about:hover  ul{
    display: block;
}

and for list structure check is question Proper way to make HTML nested list?

Upvotes: 1

Related Questions