Div悬停仅在底部工作

时间:2016-09-28 11:59:36

标签: html css

我正在尝试将div设为一个链接,在悬停时应该放大并显示另一个叠加div。这就是我所拥有的。它可以工作,但不是div的所有部分都与悬停一起工作。它只能在div的底部工作,但不能在其他任何地方工作。

请问我做错了什么?

我已将我的代码放在下面。有趣的是它如何适用于background-home-row-2并且不适用于.background-home-row-1。我在省什么?

$("a.image").hover(function() {
  $(".background-home-row-1 .visible-on-hover").css("display", "block");
}, function() {
  var mq = window.matchMedia("(min-width : 320px) and (max-width : 480px)");
  if (!mq.matches) {
    $(".background-home-row-1 .visible-on-hover").css("display", "none");
  }
});


$(".background-home-row-2").hover(function() {
  $(".background-home-row-2 .visible-on-hover").css("display", "block");
}, function() {
  var mq = window.matchMedia("(min-width : 320px) and (max-width : 480px)");
  if (!mq.matches) {
    $(".background-home-row-2 .visible-on-hover").css("display", "none");
  }
});
.image-box {
  padding: 0px;
  margin: 0px;
  display: block;
}
.background-home-row-1 .visible-on-hover,
.background-home-row-2 .visible-on-hover {
  display: none;
  width: 200px;
  height: 40px;
  position: absolute;
  top: 350px;
  left: 100px;
  padding-top: 4px;
  padding-left: 10px;
  border: none;
  background-color: red;
  background: red;
  font-family: geomanist-medium;
  font-size: 1.5em;
}
div.background-home-row-1 {
  background: url("../assets/images/home_image1.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
  -webkit-filter: grayscale(100%);
  -moz-filter: grayscale(100%);
  -o-filter: grayscale(100%);
  -ms-filter: grayscale(100%);
  filter: grayscale(100%);
}
div.image-box:hover div.background-home-row-1,
div.image-box:focus div.background-home-row-1,
div.background-home-row-1:hover,
div.background-home-row-1:focus {
  -webkit-filter: grayscale(0%);
  -moz-filter: grayscale(0%);
  -o-filter: grayscale(0%);
  -ms-filter: grayscale(0%);
  filter: grayscale(0%);
  -webkit-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
  transform: scale(1.2);
}
div.background-home-row-2 {
  background: url("../assets/images/home_image2.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
  -webkit-filter: grayscale(100%);
  -moz-filter: grayscale(100%);
  -o-filter: grayscale(100%);
  -ms-filter: grayscale(100%);
  filter: grayscale(100%);
}
div.image-box:hover div.background-home-row-2,
div.image-box:focus div.background-home-row-2,
div.background-home-row-2:hover,
div.background-home-row-2:focus {
  -webkit-filter: grayscale(0%);
  -moz-filter: grayscale(0%);
  -o-filter: grayscale(0%);
  -ms-filter: grayscale(0%);
  filter: grayscale(0%);
  -webkit-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
  transform: scale(1.2);
}
<div class="col-md-4 col-sm-6 image-box">
  <a href="#" class="white-text image">
    <div class="background-home-row-1" style="border: none;">
      <div class="visible-on-hover" style="border: none;">Click here to view</div>
    </div>
    <script>
    </script>
  </a>
</div>

<div class="col-lg-4 col-md-4 col-sm-6 image-box">
  <a href="#" class="white-text">
    <div class="background-home-row-2" style="border: none;">
      <div class="visible-on-hover" style="border: none;">Click here to view</div>
    </div>
  </a>
</div>

0 个答案:

没有答案