无法隐藏菜单中的项目

时间:2016-11-28 17:03:30

标签: css navigation hidden display

所以,我想出了一个简单的资产净值,而我正在尝试添加一个仅在屏幕较小时显示的汉堡图标。

目前,我的汉堡只是单词Menu,但我希望默认情况下隐藏它。但是,我的代码被显示重写:inline,即代码中的早期代码。即使我添加!重要。

任何人都对如何隐藏菜单元素有任何想法?

JSFIDDLE https://jsfiddle.net/Lwwgpx9k/

我的代码如下。

html的

<div class="nav">
   <ul>
    <li class="hidden">Menu</li>
    <li class="home"><a class="active" href="#">Home</a></li>
    <li class="gallery"><a href="#">Gallery</a></li>
    <li class="tutorials"><a href="#">Tutorials</a></li>
    <li class="about"><a href="#">About</a></li>
  </ul>
</div>

的CSS

    body {
  background: #333;
}

.nav ul {
  color: #e6e9e9;
  position: fixed;
  top: 60px;
  padding-left: 5%;
  text-align: center;
  margin: 0;
}

.nav ul li {
  line-height: 35px;
  float: left;
  width: 120px;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 0px 10px;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -ms-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
}

.nav ul li:hover {
  background: #6A1B9A;
  color: #e6e9e9;
}

.nav ul li ul {
  padding: 0;
  position: absolute;
  top: 35px;
  left: 0;
  text-align: left;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.5s;
  -moz-transition: opacity 0.5s;
  -ms-transition: opacity 0.5s;
  -o-transition: opacity 0.5s;
  -transition: opacity 0.5s;
}

.nav ul li ul li {
  width: 200px;
  background: #555;
  display: block;
  color: #e6e9e9;
}

.nav ul li ul li:hover {
  background: #6A1B9A;
}

.nav ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
  transition-delay: 2s;
  -webkit-transition-delay: 2s;
  /* Safari */
}

.nav a {
  font-size: 1.4em;
  text-decoration: none;
  color: #e6e9e9;
  display: block;
  transition: .3s background-color;
}

.nav a:hover {
  background-color: #6A1B9A;
  color: #e6e9e9;
}

.nav a.active {
  background-color: #6A1B9A;
  color: #e6e9e9;
  cursor: default;
}

.nav ul {
  color: #e6e9e9;
  position: fixed;
  top: 60px;
  padding-left: 5%;
  text-align: center;
  margin: 0;
}

.nav ul li {
  line-height: 35px;
  float: left;
  width: 120px;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 0px 10px;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -ms-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
}

.nav ul li:hover {
  background: #6A1B9A;
  color: #e6e9e9;
}

.nav ul li ul {
  padding: 0;
  position: absolute;
  top: 35px;
  left: 0;
  text-align: left;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.5s;
  -moz-transition: opacity 0.5s;
  -ms-transition: opacity 0.5s;
  -o-transition: opacity 0.5s;
  -transition: opacity 0.5s;
}

.nav ul li ul li {
  width: 200px;
  background: #555;
  display: block;
  color: #e6e9e9;
}

.nav ul li ul li:hover {
  background: #6A1B9A;
}

.nav ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
  transition-delay: 2s;
  -webkit-transition-delay: 2s;
  /* Safari */
}

.nav a {
  font-size: 1.4em;
  text-decoration: none;
  color: #e6e9e9;
  display: block;
  transition: .3s background-color;
}

.nav a:hover {
  background-color: #6A1B9A;
  color: #e6e9e9;
}

.nav a.active {
  background-color: #6A1B9A;
  color: #e6e9e9;
  cursor: default;
}

.hidden {
  display: none; !important
}

1 个答案:

答案 0 :(得分:1)

你的问题在这里

hidden {
  display: none; !important<---- this important should be inside ";"
}

应该是

hidden {
  display: none !important; 
}