CSS:悬停标签不起作用? display:none to inline-block

时间:2017-01-27 17:12:27

标签: html css

我正在为网站创建导航菜单... 我使用css:hover函数将display标记从none更改为inline-block

我之前已经多次这样做了,完全没有问题。但现在它似乎不起作用。

这是我最简单的代码: 当.parent div元素悬停时,.child div元素应该出现。

任何人都知道为什么不这样做?



a {
  text-decoration: none;
  color: #000;
  font-size: 20px;
}
.parent {
  width: 200px;
  height: 100px;
  background-color: #999;
  display: inline-block;
}
.child {
  display: none;
  width: 200px;
  height: 100px;
  background-color: #333;
}
.parent:hover .child {
  display: inline-block;
}

<a href="">
  <div class="parent">Parent</div>
</a>
<a href="">
  <div class="child">Child</div>
</a>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

试试这个)

<a href="">
  <div class="parent">Parent</div>
</a>
<a href="">
  <div class="child">Child</div>
</a>

a {
  text-decoration: none;
  color: #000;
  font-size: 20px;
}
.parent {
  width: 200px;
  height: 100px;
  background-color: #999;
  display: inline-block;
}
.child {
  display: none;
  width: 200px;
  height: 100px;
  background-color: #333;
}
a:hover + a .child {
  display: inline-block;
}

直播 - https://jsfiddle.net/d26L7juy/

答案 1 :(得分:0)

将孩子放入父母 - 悬停工作不需要链接:

&#13;
&#13;
a {
  text-decoration: none;
  color: #000;
  font-size: 20px;
}
.parent {
  width: 200px;
  height: 100px;
  background-color: #999;
  display: inline-block;
}
.child {
  display: none;
  width: 200px;
  height: 100px;
  background-color: #333;
}
.parent:hover .child {
  display: inline-block;
}
&#13;
<div class="parent">Parent
  <a href="">
    <div class="child">Child</div>
  </a>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

您的孩子div不在父Div中。

  <div class="parent">
   <div class="child">
   </div>
 </div>

答案 3 :(得分:0)

<a href="" class="parent">
  <div>Parent</div>
</a>
<a href="" class="child">
  <div>Child</div>
</a>

.parent:hover + .child {
  display: inline-block;
}
相关问题