我正在创建2个盒子,在悬停时淡入淡出但我希望文本保持完全白色而不会随背景/图像淡化。我在编码方面不是很先进,但如果可能的话,任何帮助都会受到赞赏和现场演示吗?
CSS
.image {
position:relative;
width:400px;
height:200px;
background-color:#555555;
color: #ffffff;
}
.image img {
width:50%;
vertical-align:top;
color: #ffffff;
}
.image:after, .image:before {
position:absolute;
background-color:rgba (255,0,0,1);
opacity:0;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
color: #ffffff;
}
.image:after {
content:'\A';
width:100%; height:100%;
top:0; left:0;
background-color:rgba(255,0,0,0.75);
color:#ffffff;
}
.image:before {
width:50%;
color:#fff;
z-index:1;
bottom:0;
padding:4px 10px;
text-align:center;
background-color:red;
box-sizing:border-box;
-moz-box-sizing:border-box;
color: rgba(255,255,255,0);
}
.image:hover:after, .image:hover:before {
opacity:1;
}
.text {
padding-left:210px;
padding-right:10px;
margin-top:-190px;
color:rgba(255,255,255,10);
font-family:Arial;
font-size:15px;
opacity: 1;
}
HTML
<div class="image">
<img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.</p>
</div>
</div>
<hr>
<div class="image">
<img src="http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.
</div>
</div>
答案 0 :(得分:0)
在这里,你去我的朋友,我把它放在小提琴中,如果它有问题,或者不是你想要它做的话,它会让我知道。这是一个链接
.image {
position:relative;
width:400px;
height:200px;
background-color:#555555;
color: #ffffff;
}
.image img {
width:50%;
vertical-align:top;
color: #ffffff;
}
.image:after, .image:before {
position:absolute;
background-color:rgba (255,0,0,1);
opacity:0;
transition: 0.5s ease;
-webkit-transition: 0.5s ease;
color: #ffffff;
}
.image:after {
content:'\A';
width:100%; height:100%;
top:0; left:0;
background-color:rgba(255,0,0,0.75);
color:#ffffff;
}
.image:before {
width:50%;
color:#fff;
z-index:1;
bottom:0;
padding:4px 10px;
text-align:center;
background-color:red;
box-sizing:border-box;
-moz-box-sizing:border-box;
color: rgba(255,255,255,0);
}
.image:hover:after, .image:hover:before {
opacity:.5;
}
.text {
padding-left:210px;
padding-right:10px;
margin-top:-190px;
color:rgba(255,255,255,10);
font-family:Arial;
font-size:15px;
opacity: 1;
position:relative;
z-index:1;
}
答案 1 :(得分:0)
由于您希望将文本放在前面,只需使用z-index
在CSS上添加:
.text {
position:relative;
z-index:1;
}
选中此Demo Fiddle
如果您想要前面的图片也使用相同的属性http://jsfiddle.net/2qekazm4/2/
答案 2 :(得分:0)
让我们首先进入概念。
不透明度可设置当前块中设置了不透明度的所有对象的不透明度。
因此,要解决此问题,请不要使用OPACITY。而是使用rgba。
在CSS中:
#outer-container {
background: url(../img/image.jpg) no-repeat center fixed;
position: relative;
color: #fff;
}
#inner-container-for-alpha {
filter: alpha(opacity=60);
background: rgba(43,255,113, 0.6); }
html 中的外部容器和内部容器如下:
<div class="row" id="outer-container">
<div id="inner-container-for-alpha ">
<h1> This is text over image and it will not get faded </h1>
</div>
</div>