html - 图像叠加在响应大小的图像 Bootstrap 上

标签 html css responsive-design twitter-bootstrap-3

我正在尝试创建一个响应式图像网格(带有描述),当鼠标悬停在该网格上时将有一个颜色叠加层(只是图像而不是文本)。由于图像的响应高度,我遇到了叠加层覆盖所有内容而不仅仅是图像的问题。

有什么办法可以解决这个问题吗?

为了便于理解,我在这里重现了这个问题:http://jsfiddle.net/r8rFc/

这是我的 HTML:

<div class="row">

    <div class="col-xs-12 col-sm-6 col-md-3 project">
        <a href="#">
            <div>
                <img src="http://placehold.it/500x500" class="img-responsive"/>
                <div class="fa fa-plus project-overlay"></div>
            </div>
            <div style="text-align:center;">
                <h3>Project name</h3>
                <p>Image description</p>
            </div>
        </a>
    </div>

</div>

还有我的 CSS:

.project-overlay {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(41,128,185,0.9);
    color: #fff;
    padding: 50%;
}

提前致谢!

最佳答案

向包含的 div 添加一个类,然后在其上设置以下 css:

.img-overlay {
    position: relative;
    max-width: 500px; //whatever your max-width should be 
}

position: relative 在具有 position: absolute 的子元素的父元素上是必需的,以便子元素相对于该父元素定位。

DEMO

关于html - 图像叠加在响应大小的图像 Bootstrap 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33257416/

相关文章:

javascript - 使用 jQuery 单击文本区域时打开一个弹出窗口

javascript - Firefox 不会触发动态嵌套 iframe 的 onload

html - 在 Chrome 中调整 flexbox 大小时避免滚动条?

jquery - 无法更改 Bootstrap 表的宽度

javascript - 用线条分割网页

html - 是否建议在使用 Bootstrap 时使用媒体查询

css - 在 twitter bootstrap 中使用不同的字体

html - Font Awesome 图标无法在浏览器中正确显示

html - CSS 内容属性在 IE 中不起作用

javascript - 仅在移动设备上加载部分内容