在图像和文本块上重新创建Adobe Portfolio双悬停效果

问题描述 投票:0回答:2

香港专业教育学院一直试图重新创建https://andreas-demo.myportfolio.com/上的悬停双重效果

然而,我似乎无法让两者正确对齐然后我无法获得悬停在整个部分上的影响但是改变两者:1-使图像变暗,2 - 反转颜色。

我希望能够在将鼠标悬停在整个块上时发生两种影响,就像在^上面的网站上一样。

这是我的代码;

img {
  display: block;
  width: 60%;
  height: 450px;
  background-color: #f2f2f2;
  !important;
  -webkit-filter: brightness(100%);
}

a img:hover {
  -webkit-filter: brightness(60%);
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
  transition: all 1s ease;
}

.media {
  background-color: #f2f2f2;
  !important;
  text-align: center;
}

p {
  display: inline-block;
  vertical-align: middle;
}
<div class="container">
  <a href="">
    <div class="media">
      <img src="img/pexels-photo-733438.jpeg" class="img-fluid" alt="Responsive image">
      <p>PROJECT 1</p>
      <p>2017</p>
    </div>
  </a>
</div>
javascript html css hover
2个回答
0
投票

在容器上:悬停,将容器'背景颜色设置为黑色(默认为白色),并将图像不透明度设置为0.5。


0
投票

:hover伪类移动到3个父(包装)元素之一 - .container.container > a.media元素。这将为:hover上的两个元素添加叠加效果。

像这样:

.container {
  font-family: Arial;
}

.container:hover {
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
  transition: all 1s ease;
}


.container__link {
  display: flex;
  text-decoration: none;
}

.media {
  flex: 6;
  background-color: #222222;
}

img {
  display: block;
  width: 100%;
  height: 450px;
  opacity: 1;
  -webkit-transition: all 1s ease;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
  transition: all 1s ease;
}

.container:hover .media img {
  opacity: 0.3;
}


.description {
  flex: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  -moz-transition: all 1s ease;
  -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
  transition: all 1s ease;
  background-color: #ffffff;
  color: #222222;
}

.container:hover .description {
  background-color: #222222;
  color: #ffffff;
}

p {
  padding: 0;
  margin: 0;
}
<div class="container">
  <a href="" class="container__link">
    <div class="media">
      <img src="http://via.placeholder.com/350x150" class="img-fluid" alt="Responsive image">
    </div>
    <div class="description">
      <p>PROJECT 1</p>
      <p>2017</p>
    </div>
  </a>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.