简体   繁体   English

css (html) 中图片叠加的问题

[英]Problem with overlay on picture in css (html)

I have problem with adding overlay on image in my html project.我在我的 html 项目中在图像上添加叠加层时遇到问题。 It should looks like overlay coming from bottom of image when it's hovered, but instead it's only like link on all the image.当它悬停时,它应该看起来像来自图像底部的叠加层,但它只是像所有图像上的链接。 Here is code from html and css:这是来自 html 和 css 的代码:

 .tile5 { width: 480px; margin: 10px; height: 304px; float: left; } .overlay { position: relative; width: 480px; height: 304px; } .overlay .link { position: absolute; display: block; width: 100%; height: 100%; background-color: #111; left: 0px; top: 0px; opacity: 0; transition: opacity 0.5s ease-in-out; } .overlay:hover .link { opacity: 0, 8; }
 <div class="square"> <div class="tile5"> <div class="overlay"> <a href="#"> <img src="grafika/obraz.jpg" style="width: 480px; height: 304px; border-radius: 10px;" /> </a> <a href="#" class="link">tekkst teskttekkst teskttekkst teskttekkst teskttekkst teskt</a> </div> ...other element in div 'square' </div>

I hope someone will help;)我希望有人会帮助;)

You could try something like this:你可以尝试这样的事情:

 .tile5 { width: 480px; margin: 10px; height: 304px; float: left; position:relative; } .overlay { position: relative; width: 480px; height: 304px; } .overlay .link { position: absolute; display: block; background-color: rgba(0, 0, 0, 0.4); left: 0px; top: 40%; opacity:0; transition: opacity 0.5s ease-in-out; z-index:99999; color:white; padding:10px 20px; text-decoration:none; } .overlay:hover .link { opacity: 0.8; }
 <div class="square"> <div class="tile5"> <div class="overlay"> <a href="#"> <img src="https://images.pexels.com/photos/206959/pexels-photo-206959.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" style="width: 480px; height: 304px; border-radius: 10px;" /> </a> <a href="#" class="link">tekkst teskttekkst teskttekkst teskttekkst teskttekkst teskt</a> </div> ...other element in div 'square' </div>

Looks like your HTML structure a bit off.看起来您的 HTML 结构有点偏离。 The tag with class overlay.带有类覆盖的标签。

Here's how I would go about it.这就是我将如何去做。 I think you are trying to have an image caption visible on hover我认为您正在尝试在悬停时显示图像标题

HTML HTML

 <div class="square">
        <a href="#"> 
          <img src="grafika/obraz.jpg" style="width: 480px; height: 304px; border-radius: 10px;"/>
          <span>Caption Here</span>
        </a>
</div>

CSS CSS

.square{
    position: relative;
    width: 480px;
    height: 304px;
    float: left;
}
.square a span{
  background:#efebeb;
  max-width: 480px;
  width:100%;
  color:#000;
  padding:20px 0px;
   position: absolute;
   left:0;
   bottom:0;
   opacity: 0;
   transition: opacity 0.5s ease-in-out;
   text-align:center;
}
.square a:hover span{
  opacity: 0.8;
}

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM