簡體   English   中英

懸停圖像疊加

[英]Image overlay on hover

我正在嘗試在圖像上顯示覆蓋圖。 但是我不知道如何使該圖像懸停在現有圖像上。 我嘗試更改z-index,位置,但未顯示疊加層。 我是CSS的新手,請嘗試幫助我解決這個問題。

HTML:

<section class="home-item">
  <article class="home-item" data-category="RS">
    <div class="box">
      <div class="overlay">
        <a href="#">
          <span class="boximg" id="home">
            <img width="403px" height="270" src="https://images.pexels.com/photos/186077/pexels-photo-186077.jpeg"/>
          </span>
        </a>
      </div>
      <br>      
      <p id="caption">St. Ruperts Residence</p>
    </div>
  </article>
</section>

CSS:

.box {
  max-width: 403px;
  color: #000 !important;
  position:relative;
  padding:0;
  margin-bottom:0px;
}

.box > a
.box span,
.box img {
  display:block;
}

#caption {
  width: 403px;
  font-size: 15px;
  text-decoration: none;
  margin: -15px 0 40px 5px !important;
  font-weight: 600;
  font-family:Roboto !important;

}

.boximg {
  width: auto;
  max-width: 100%;
}

.box:hover {
  width: auto;
  max-width: 450px;
  color: #fff !important;
  z-index:2;
  background-color:#000;
}

.home-item{
  width:403px;
}

.home-item:hover .overlay{
  background-image:url('https://www.ixds.com/system/files/media-images/pre-work-talk-polygone-012x_0.png');
  position:relative;
  z-index:9999999999999999999;
  display:block;
}

請查看https://jsfiddle.net/6vrcv9kk/1/

謝謝堆!

您可以通過html制作。存在一些html標記錯誤,因此我也糾正了結構。

 .box { max-width: 403px; color: #000 !important; position:relative; padding:0; margin-bottom:0px; } .box > a .box span, .box img { display:block; } #caption { width: 403px; font-size: 15px; text-decoration: none; margin: -15px 0 40px 5px !important; font-weight: 600; font-family:Roboto !important; } .overlay .hover { position: absolute; top: 0; left: 0; } .boximg { /* width: auto; max-width: 100%; */ display: block; height: 270px; } .box:hover img { display: none; height: 270px; object-fit: cover; } .box:hover .hover { display: block; } .home-item{ width:403px; } 
 <section class="home-list"> <article class="home-item"> <div class="box"> <div class="overlay"> <a href="#"> <span class="boximg" id="home"> <img width="403px" height="270" src="https://images.pexels.com/photos/186077/pexels-photo-186077.jpeg" /> <img class="hover" width="403px" height="270" src="https://www.ixds.com/system/files/media-images/pre-work-talk-polygone-012x_0.png" /> </span> </a> </div> <br> <p id="caption">St. Ruperts Residence</p> </div> </article> </section> 

試試這個,希望對您有幫助:

<section class="home-item">
  <article class="home-item" data-category="RS">
    <div class="box" >
  <div class="overlay">
  <a href="#">
    <span class="boximg" id="home"><img width="403px" height="270" src="https://images.pexels.com/photos/186077/pexels-photo-186077.jpeg" /></span></a>
   </div>
    <br>

  <p id="caption">St. Ruperts Residence</p>
</article>
<style>
.box {
  max-width: 403px;
  color: #000 !important;
  position:relative;
  padding:0;
  margin-bottom:0px;
}

.box > a
.box span,
.box img {
 display:block;
}

#caption {
     width: 403px;
    font-size: 15px;
    text-decoration: none;
    margin: -15px 0 40px 5px !important;
    font-weight: 600;
    font-family:Roboto !important;

}

.boximg {
  width: auto;
  max-width: 100%;
}

.box:hover {
  width: auto;
  max-width: 450px;
  color: #fff !important;
  z-index:2;
  background-color:#000;
  opacity: 0.3;
}

.home-item{
  width:403px;
  opacity: 1;
}

/*.home-item:hover .overlay{
  background-image:url('https://www.ixds.com/system/files/media-images/pre-work-talk-polygone-012x_0.png');
  position:relative;
  z-index:9999999999999999999;
display:block;
}*/
</style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM