我一直在尝试将鼠标悬停在一张照片上,这张照片会使背景变暗并将文字带到最上面。
然后我想要一个很好的集中文本,当我被遗弃时。
这两件事都实现了,但后来遇到了两个小问题。
<div id="bottomWide">
<ul>
<li class="first">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
<span class="title">A Heading</span><br>
<span class="text">Couples of Lines of Text will come here</span><br>
<span class="shop">See Details.</span>
</div>
</div>
</li>
<li class="second">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
Some text here, style as needed
</div>
</div>
</li>
</ul>
</div>
#bottomWide{
width:100%;
margin:0 auto;
}
#bottomWide ul{
margin:0;
padding:0;
}
#bottomWide li{
list-style-type: none;
display: inline-block;
width:50%;
text-align:justify;
float: left;
/* For Mouse Over*/
position: relative;
display: inline-block;
}
#bottomWide li:last-child img {
border-left: 4px solid #fff;
}
#bottomWide img{
width:100%;
}
#bottomWide li div.all-canvas{
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 */
margin: 0 auto;
}
#bottomWide li:last-child div.all-canvas {
margin-left: 4px;
}
#bottomWide li div.all-canvas:hover {
opacity: 0.7;
}
#bottomWide li:last-child div.all-canvas:hover {
opacity: 0.7;
margin-left: 4px;
}
div.all-text {
height:358px; /* This is what I want to change to %*/
width: 623px; /* This is what I want to change to %*/
text-align:center;
border:1px solid silver;
display: table-cell;
vertical-align:middle;
margin: 0 auto;
}
div.all-text span.title { padding: 3px; font: 18px/1.35 "Open Sans", Helvetica, sans-serif; text-transform: uppercase;}
输出看起来像这样: -
(注意图片顶部的暗淡文字;希望使其固定) 感谢。
答案 0 :(得分:2)
如果为元素设置不透明度,则所有子元素(包括文本)也将具有不透明度。您可以尝试使用rgba:
更改背景颜色#bottomWide li div.all-canvas:hover {
background-color: rgba(0,0,0, 0.7);
}
您仍然需要将不透明度0切换为1以使其可见,但背景颜色应该是透明的。
将文本置于中心将会更加棘手,因为您正在尝试使其具有响应性。由于文本没有固定的高度,您可能必须使用Javascript来计算它。你可以从这个CSS开始:
.theText {
position: absolute;
top: 50%;
margin-top: -20px; // Should be half of the element height
}
你必须使用javascript来衡量.theText的高度并相应地设置一个负边距顶部...