父悬停时显示类型未更改

时间:2020-11-10 17:54:26

标签: html css

我正在尝试制作一个可沿箭头方向更改div的滑块。除非您将鼠标悬停在父div上方,否则箭头不可用。但是,只有当我将鼠标悬停在父div的图像的右侧时,箭头才可用。同样,字幕链接上的悬停也不起作用。任何帮助将不胜感激。

/*Background*/

.collection {
    height: 400px;
    position: relative;
    background-image: url('http://www.cliometrics.com/bbw/images/slider/bg/2.png');
    background-repeat: no-repeat;
    background-size: 120%;
    position: relative;
    z-index: -1;
    font-family:  'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/*Title*/
.collection p span {
    display: block;
    font-size: 50px;
    font-weight: 600;
    position: relative;
    top: 50px;
    left: 30px;
}
.collection p span:last-of-type {
    color: rgb(255, 0, 0);
    position: relative;
    bottom: 15px;
}

/*Subtitle*/
.collection a {
    display: block;
    text-decoration: none;
    color: rgb(0, 0, 0);
    font-size: 20px;
    transition: color 250ms;
    position: relative;
    top: 60px;
    left: 30px;
}
.collection a:hover {color: rgb(255, 0, 0);}

/*Arrows for shifting*/
#collection_shifter {
    position: absolute;
    top: 100px;
    width: 100%;
    font-size: 70px;
    color: rgb(10, 10, 10);
}

/*Left Arrow*/
#collection_shifter i:first-of-type {
    position: absolute;
    left: 50px;
    z-index: 1;
    display: none;
}
.collection:hover #collection_shifter i:first-of-type {
    display: inline-block;
    left: 50px;
}

/*Right Arrow*/
#collection_shifter i:last-of-type {
    position: absolute;
    right: 30px;
    z-index: 1;
    display: none;
}
.collection:hover #collection_shifter i:last-of-type {
    display: inline-block;
    right: 30px;
}
<link rel="stylesheet" href="https://kit-pro.fontawesome.com/releases/v5.15.1/css/pro.min.css">
<div class="collection">
  <div id="collection_shifter">
    <i class="far fa-chevron-left"></i>
    <i class="far fa-chevron-right"></i>
  </div>
  <p><span>New Books</span><span>Collection</span></p>
  <a href="#">Shop Now -</a>
</div>

1 个答案:

答案 0 :(得分:0)

看起来您的主要问题是.collection上的z-index。将其设置为-1会将元素推到其他所有元素的后面,从而使您无法将鼠标悬停在上面。

删除z-index似乎使事情按您想要的方式工作。这是你要的吗?

Create
/*Background*/

.collection {
  height: 400px;
  position: relative;
  background-image: url('http://www.cliometrics.com/bbw/images/slider/bg/2.png');
  background-repeat: no-repeat;
  background-size: 120%;
  position: relative;
  /* z-index: -1; */
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}


/*Title*/

.collection p span {
  display: block;
  font-size: 50px;
  font-weight: 600;
  position: relative;
  top: 50px;
  left: 30px;
}

.collection p span:last-of-type {
  color: rgb(255, 0, 0);
  position: relative;
  bottom: 15px;
}


/*Subtitle*/

.collection a {
  display: block;
  text-decoration: none;
  color: rgb(0, 0, 0);
  font-size: 20px;
  transition: color 250ms;
  position: relative;
  top: 60px;
  left: 30px;
}

.collection a:hover {
  color: rgb(255, 0, 0);
}


/*Arrows for shifting*/

#collection_shifter {
  position: absolute;
  top: 100px;
  width: 100%;
  font-size: 70px;
  color: rgb(10, 10, 10);
}


/*Left Arrow*/

#collection_shifter i:first-of-type {
  position: absolute;
  left: 50px;
  z-index: 1;
  display: none;
  cursor: pointer; /* optional: change the cursor when you hover over the arrow */
}

.collection:hover #collection_shifter i:first-of-type {
  display: inline-block;
  left: 50px;
}


/*Right Arrow*/

#collection_shifter i:last-of-type {
  position: absolute;
  right: 30px;
  z-index: 1;
  display: none;
  cursor: pointer; /* optional: change the cursor when you hover over the arrow */
}

.collection:hover #collection_shifter i:last-of-type {
  display: inline-block;
  right: 30px;
}