【问题标题】:CSS Menu Disappears after Hover悬停后CSS菜单消失
【发布时间】:2014-12-28 00:05:39
【问题描述】:

我正在学习 CSS,我创建了一个垂直菜单,将鼠标悬停在第一个菜单项上会显示子菜单。但我的问题是,只要我将鼠标移到子菜单,它就会消失。我怎样才能使它保持在那里,直到我单击其中一个子菜单项?请帮忙。

已经搜索了很多示例,但没有一个与此类似。我是 CSS 新手,我不确定我的方法是否适合此菜单设置要求。请赐教。

@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>

【问题讨论】:

  • @KingShimkus 你是什么意思?

标签: html css


【解决方案1】:

请参考这个小提琴: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%; 上边距:0%; 顶部:自动; 显示:内联; 列表样式类型:无; 左边距:5%; 位置:相对; z-index:0; /* [禁用]清除:无; */ }

.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;
}

对于列表结构检查是问题Proper way to make HTML nested list?

【讨论】:

  • 感谢您的回答,但子菜单又变回垂直了。
  • 只需阅读有关嵌套列表的链接。我什至没有意识到。感谢您的信息。
猜你喜欢
  • 2015-03-27
  • 1970-01-01
  • 2021-01-22
  • 2013-02-25
  • 1970-01-01
  • 2014-09-02
  • 1970-01-01
  • 2013-12-30
  • 2018-04-17
相关资源
最近更新 更多