doufu9836 2017-04-17 13:52
浏览 68

尝试使用laravel css3和bootstrap叠加图像

This is my listing.blade.php file. I want to overlay image one at a time but all my images are getting overlayed as I hover the mouse point near the image.

<div class="row contain">
    @foreach($product as $data)
        <div class="col-md-6 pad-space">
            <a href="#">
                <img src="{{ URL::to('/images/' .$data->image_1) }}"  class="image" />
            </a>
            <div class="overlay">
                <div class="text">{{$data->name}}</div>
            </div>
        </div>
    @endforeach
</div>

This is my custom.css file and am also using bootstrap3.

.selector{
  background-color:lightgrey;
  padding-left:10%;
  padding-right: 10%;
}

.pad-space{
  padding-top: 7%;
}

.contain {
  width: 50%!important;
}

.image {
  display: block;
  width: 100%;
  height: 50%;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color: #008CBA;
}

.contain:hover .overlay {
  opacity: 0.5;
}

.text {
  color: white;
  font-size: 20px;
  position: absolute;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

In my above listing file I have used @foreach to fetch the image from database. So if I hover on a specific image then it should overlay and provide a text on it.

  • 写回答

1条回答 默认 最新

  • dpdyh86002 2017-04-19 10:43
    关注

    You should change the HTML so that the overlay is within the anchor:

    <div class="row contain">
        @foreach($product as $data)
            <div class="col-md-6 pad-space">
                <a href="#">
                    <img src="{{ URL::to('/images/' .$data->image_1) }}"  class="image" />
                    <div class="overlay">
                        <div class="text">{{$data->name}}</div>
                    </div>
                </a>
            </div>
        @endforeach
    </div>
    

    And change the CSS to activate the overlay when the anchor is hovered:

    .contain a:hover .overlay {
      opacity: 0.5;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作