gpt4 book ai didi

CSS3 2x URL 的背景和一个不透明的

转载 作者:太空宇宙 更新时间:2023-11-04 07:35:29 25 4
gpt4 key购买 nike

我有这一行:

   background: url("../img/background-first-layer.png") no-repeat, url("../img/background-second-layer.png") no-repeat;

我需要添加“不透明度:0.15”,但仅适用于第二层 - 第一层未更改,也许有人知道如何写? (我想写在一个类(class))

编辑这里有示例代码:

<body>
<div class="container">
<header class="header-block" alt="code which dont want opacity">
<a class="brand"><img src="/img/brand.png" alt="code which dont want opacity"></a>
<a class="logo"><img src="img/logo.png" alt="code which dont want opacity"></a>
</header>
<div class="left-area" alt="code which dont want opacity">
<p>code which dont want opacity</p>
<section class="register-box" alt="code which dont want opacity">
<p>code which dont want opacity</p>
</section>




</div>
</body>
body {
color: #fff;
background: url("../img/background-first-layer.png") no-repeat;
background-size: cover;
}

.container {
background: url("../img/background-second-layer.png") no-repeat;
background-size: cover;
max-width: 2560px;
width: 100%;
height: auto;

}

.left-area {
padding: 55px 0 0;
text-align: center;

}

.brand {
padding-right: 24px;
width: 100%;
max-width: 112px;
opacity: 0.42;
}

最佳答案

这是一个使用伪元素的例子。伪元素 (::before) 绝对放置在原始容器内,背景图像的 z-index 设置为 -1,不透明度设置为 0.42。这样你的内容就不会受到不透明度的影响,并且在它上面,所以用户可以与之交互。

现在您也可以在原始 div 中使用另一个 div 来实现此目的(只需放置一个空的 div/span 并为其赋予与伪元素相同的样式减去 content: "")但我不确定您是否可以编辑 html

我添加了背景颜色,这样你就可以清楚地看到发生了什么

body {
color: #fff;
background: green url("../img/background-first-layer.png") no-repeat;
background-size: cover;
}

.container {
max-width: 2560px;
width: 100%;
height: auto;
position: relative;
}
.container::before {
background: gray url("../img/background-second-layer.png") no-repeat;
background-size: cover;
content: " ";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0.42;
z-index: -1;
}

.left-area {
padding: 55px 0 0;
text-align: center;
}

.brand {
padding-right: 24px;
width: 100%;
max-width: 112px;
}
<div class="container">
<header class="header-block" alt="code which dont want opacity">
<a class="brand"><img src="/img/brand.png" alt="code which dont want opacity"></a>
<a class="logo"><img src="img/logo.png" alt="code which dont want opacity"></a>
</header>
<div class="left-area" alt="code which dont want opacity">
<p>code which dont want opacity</p>
<section class="register-box" alt="code which dont want opacity">
<p>code which dont want opacity</p>
</section>
</div>

关于CSS3 2x URL 的背景和一个不透明的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48995015/

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