gpt4 book ai didi

html - 阻止文本随背景颜色一起褪色

转载 作者:行者123 更新时间:2023-11-28 09:23:13 26 4
gpt4 key购买 nike

我正在创建 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>

最佳答案

因为你想让文本保持在前面,只需使用 z-index 将它添加到你的 CSS 中:

.text {
position:relative;
z-index:1;
}

检查这个Demo Fiddle

如果您也想要前面的图像,请使用相同的属性 http://jsfiddle.net/2qekazm4/2/

关于html - 阻止文本随背景颜色一起褪色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25996639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com