gpt4 book ai didi

html - 在不更改文本的情况下将 div 背景的不透明度设置为透明

转载 作者:可可西里 更新时间:2023-11-01 13:49:13 25 4
gpt4 key购买 nike

如何设置 div 背景的不透明度而不影响 hero-text 中的文本?现在 hero-text 继承了 ion-slide 的不透明度。

<style>
.slider {
height: 100%;
width: 100%;
}
.slide {
background-size: cover;
}
#one {
background: url(img/walkthrough-1.png) no-repeat;
opacity: 0.5;
}
#two {
background: url(img/walkthrough-2.png) no-repeat;
}
#three {
background: url(img/walkthrough-3.png) no-repeat;
}
.splash {
bottom: 0px;
}
.hero-text {
}
</style>

<ion-content class="splash" scroll="false">
<ion-slide-box on-slide-changed="slideHasChanged($index)">
<ion-slide id="one"><div class="hero-text">Test</div></ion-slide>
</ion-slide-box>
</ion-content>

最佳答案

如果只需要调整<ion slide id="xxx">的不透明度那么我建议打破你的.hero-text根据需要划分和调整您的样式,以保持您的设计正确。

使用 CSS,您可以调整背景颜色的不透明度 -- background-color: rgba(0, 0, 0, 0.5) -- 这将创建一个 50% 不透明的黑色背景颜色,并且不会影响任何子元素。但是如果你想减少背景图像的不透明度那么你唯一的方法就是使用 opacity这当然会影响 child 。

我在一个也使用“英雄图片”的网站上使用了相同的概念,我希望背景图片淡入/淡出而不影响任何文本。您可能需要使用以下 CSS 来正确放置所有内容:

.hero-wrapper {
position: relative;
}

.hero-wrapper > .bg {
background: ...;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 0;
}

.hero-wrapper > .text {
position: relative;
z-index: 10;
}

这应该可行,尽管它是徒手绘制的。如果您希望我再解释一下或提供一个工作示例,请告诉我。干杯~

编辑

这是我通过 Plnkr 推荐的一个工作示例 :) Plnkr Demo

关于html - 在不更改文本的情况下将 div 背景的不透明度设置为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37093709/

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