O diagrama de efeito de exibição real é o seguinte
1. O fundo é transparente e a fonte é opaca é o primeiro divNotOpacity
Estilo: plano de fundo: rgba (0, 0, 0, 0,7);
Os três primeiros são os valores de cor de rgb e o último é a transparência da cor de fundo (0-1)
2. A fonte é divOpacity transparente
Estilo: cor: rgba (255,255,255,0,5);
A transparência da fonte usa cor, os três primeiros são o valor da cor de rgb, e o último é a transparência da fonte 0-1
Lembre-se: use uma cor de fonte transparente e transparência de fundo, a fonte usada é um fundo opaco .
Exemplo:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>h5结构</title>
<style type="text/css">
.divNotOpacity{
left: 200px;
top: 200px;
position: absolute;/* 绝对定位 */
/* 以下为本身div的样式 */
height: 50px;
width: 400px;
bottom: 0;
color: #ffffff;
background: rgba(0, 0, 0, 0.7); /* 背景透明,字体不透明(前三个值为rgb色素,后面的值为背景的透明度0-1) */
display: flex;/* 设置为弹性布局 */
justify-content: space-around;/* 内容左右居中显示 */
align-items: center; /* 内容上下居中显示 */
}
.divOpacity{
left: 200px;
top: 300px;
position: absolute;/* 绝对定位 */
/* 以下为本身div的样式 */
height: 50px;
width: 400px;
background:black;
color:rgba(255,255,255,0.5); /* 字体透明使用color,前三个是rgb,后面是字体的透明度0-1 */
display: flex;/* 设置为弹性布局 */
justify-content: space-around;/* 内容左右居中显示 */
align-items: center; /* 内容上下居中显示 */
}
</style>
</head>
<body>
<div class="divNotOpacity">
背景透明,字体显示在最上面,不透明
</div>
<div class="divOpacity">
字体是透明的
</div>
</body>
</html>