简体   繁体   English

通过Bootstrap使div带有图像/文本悬停叠加层的完全响应

[英]Make div with image/text hover overlay fully responsive through Bootstrap

I have hit a snag in my design and have exhausted my options on it. 我在设计中遇到了障碍,并用尽了所有的选择。 Essentially I'm designing through the Bootstrap framework to make a set of images that have a hover overlay effect applied to each one. 本质上,我正在通过Bootstrap框架进行设计,以制作一组具有悬停效果的图像集。 The effect and the responsive images work fine when separated but when combined, I lose the responsiveness to it and it stays fixed to its 300px x 250px size. 分离时,效果和响应图像效果很好,但是结合使用时,我失去了响应能力,它固定为300px x 250px大小。

This is the type of effect I am trying to achieve ( http://mikekus.com/portfolio ) 这是我要达到的效果( http://mikekus.com/portfolio

Ive added my code into jsfiddle: http://jsfiddle.net/2BuDG/ without the bootstrap.css (since it's a huge file) 我已经将我的代码添加到jsfiddle中: http : //jsfiddle.net/2BuDG/而没有bootstrap.css(因为这是一个巨大的文件)

HTML 的HTML

<div class="container-fluid">
<div class="row">


<div class="col-xs-6 col-sm-6 col-md-4 col-lg-3"> 
<div class="view view-first">  
     <img src=" SOURCE " class="img-responsive"/>  
 <div class="mask">  
 <h2>Vector Illustrations</h2>  
 <p>Illustration, Print, Digital Art</p>  
     <a href="#" class="portfolioButton">View Project</a>  
 </div>  
</div>  
</div>

CSS 的CSS

.view {

   width: 300px;
   height: 250px;
   margin: 10px;
   float: left;
   overflow: hidden;
   position: relative;
   text-align: center;
   cursor: default;
   background: #fff;
}
.view .mask,.view .content {

   width: 300px;
   height: 250px;
   position: absolute;
   overflow: hidden;
   top: 0;
   left: 0;
}

.view img {
  display: block;
  max-width: 100%;
  height: 100%; 

}

I like how the "img-responsive" class for the default img bootstrap class works but with the addition of the overlay div, it's not working. 我喜欢默认img bootstrap类的“ img响应式”类如何工作,但是添加了overlay div后,它不起作用。 I think I'm almost there but I've brain farted on this hard. 我想我快要到了,但是我已经为此付出了努力。 Thanks in advance! 提前致谢!

If you take a look at the code of the portfolio you linked to, you'll see: 如果您查看链接到的投资组合的代码,则会看到:

<li>
    <a href="/portfolio/Title">
    <img src="SOURCE" class='js-img'>
        <div class="excerpt">
            <h3>Title</h3>
            <p>Blah blah blah</p>
        </div>
    </a>
</li>

The author never assigns a fixed width or height to the <li> elements. 作者从未分配一个固定的宽度或高度的<li>元素。 He sets width: 25% to keep four images per row and assigns max-width: 480px He also sets width: 100% on the <img> elements. 他设置width: 25%以每行保留四张图像,并分配max-width: 480px他还在<img>元素上设置width: 100%

He uses media queries to change both the width and max-width of the <li> elements dependent on the screen size. 他使用媒体查询来改变宽度和的最大宽度两者<li>依赖于屏幕尺寸的元件。 You can use the following portion of Bootstrap to help you create those media query breakpoints for resizing your portfolio elements: 您可以使用引导程序的以下部分,以帮助您创建这些媒体查询断点调整你的投资组合要素:

http://getbootstrap.com/css/#grid-less http://getbootstrap.com/css/#grid-less

And you'll probably want to set your divs and imgs to a variable percentage based widths instead of fixed. 你可能会想你的div和IMGS设置为基于可变宽度的百分比,而不是固定的。

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

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