CSS menu disappears after hover

I am learning css and I created a vertical menu, hover over the first menu item, showing a submenu. But my problem is that as soon as I move the mouse in the submenu, it disappears. How can I make it stay there until I click one of the submenu items? Please, help.

Many examples have already been viewed, but there was nothing of the kind. I am new to css and I'm not sure if my approach is appropriate to this menu setting 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>
Run codeHide result
+4
source share
1 answer

Refer to this script: 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 {       : 25%;       margin-top: 0%;       top: auto;       display: inline;       list-style-type: none;       margin-left: 5%;       : ;       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;
}

- HTML?

+1

Source: https://habr.com/ru/post/1569134/


All Articles