RGi*_*kes 19 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>
Run Code Online (Sandbox Code Playgroud)
我的CSS:
.project-overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(41,128,185,0.9);
color: #fff;
padding: 50%;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
bro*_*aha 37
将类添加到包含div,然后在其上设置以下css:
.img-overlay {
position: relative;
max-width: 500px; //whatever your max-width should be
}
Run Code Online (Sandbox Code Playgroud)
position: relative在子元素的父元素上是必需的,子元素的position: absolute位置与父元素相关.