我正在尝试实现将鼠标悬停在图片上的效果,该图片会使背景变暗并在顶部显示文本。
例如,您可以访问此页面并向下滚动以查看第二组两张图片。当您将鼠标悬停在它们上时,它们会变暗并显示文本。
想到的一件事是用鼠标悬停改变图片,但这是一种矫枉过正。我希望通过 CSS 来实现它。
HTML
<div id="bottomWide">
<ul>
<li>
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div>Some text here, style as needed</div>
</li>
<li>
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div>Some text here, style as needed</div>
</li>
</ul>
</div>
CSS
#bottomWide{
width:100%;
margin:0 auto;
}
#bottomWide ul{
margin:0;
padding:0;
/* For Mouse Over*/
position: relative;
display: inline-block;
}
#bottomWide li{
list-style-type: none;
display: inline-block;
width:50%;
text-align:justify;
float: left;
}
#bottomWide img{
width:100%;
}
#bottomWide li div{
position: absolute;
top: 0;
left: 0;
/* 100% will equal the dimensions of the image, as nothing else will be inside the .container */
width: 100%;
height: 100%;
color: #fff;
background-color: #000;
opacity: 0;
/* This will create the fade effect */
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
/* Include all required vendor prefixes for opacity and transition */
}
#bottomWide li div:hover {
opacity: 0.7;
}