当我将鼠标悬停在图像上时,为什么它不起作用?

时间:2017-06-08 06:48:49

标签: css css3

一旦我得到提示,我确定这是非常愚蠢的,但我不明白为什么悬停不起作用。我添加了jQuery只是为了检查它是否适用于点击。



$(document).on("click", ".figure", function() {
  $(".popover").css("opacity", "1");
})

.container {
  position: relative;
}

.popover {
  background-color: blue;
  position: absolute;
  top: 0;
  left: 200px;
  opacity: 0;
  transition: opacity 0.5s ease-in-out 0s;
}

.figure:hover .popover {
  opacity: 1;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='container'>
  <div class='figure'>
    <img src='https://placehold.it/100' />
  </div>
  <div class='popover'>
    <p>
      Bla bla
    </p>
  </div>
</div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

因为您的.popover div不是.figure div。

的孩子

使用了+选择器

&#13;
&#13;
$(document).on("click", ".figure", function() {
  $(".popover").css("opacity", "1");
})
&#13;
.container {
  position: relative;
}

.popover {
  background-color: blue;
  position: absolute;
  top: 0;
  left: 200px;
  opacity: 0;
  transition: opacity 0.5s ease-in-out 0s;
}

.figure:hover + .popover {
  opacity: 1;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='container'>
  <div class='figure'>
    <img src='https://placehold.it/100' />
  </div>
  <div class='popover'>
    <p>
      Bla bla
    </p>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

更改

"config": {
    ...
    "ionic_rollup": "./config/rollup.config.js",
    "ionic_cleancss": "./config/cleancss.config.js",
    ...
  },

收件人:

.figure:hover .popover {
  opacity: 1;
}

答案 2 :(得分:-1)

尝试将类更改为id而不是将其悬停。

<强> JSFiddle link

#figure:hover + #popover {
   opacity:1;
}