css establece el fondo transparente del texto opaco y la fuente de fondo transparente escritura opaca

El diagrama de efectos de visualización real es el siguiente

 

1. El fondo es transparente y la fuente es opaca es el primer divNotOpacity

Estilo: fondo: rgba (0, 0, 0, 0.7);

Los tres primeros son los valores de color de rgb y el último es la transparencia del color de fondo (0-1)

2. La fuente es divOpacity transparente

Estilo: color: rgba (255,255,255,0.5);

La transparencia de la fuente usa color, los tres primeros son el valor de color de rgb y el último es la transparencia de la fuente 0-1

Recuerde: use un color de fuente transparente y transparencia de fondo, la fuente utilizada es un fondo opaco .

Ejemplo:

<!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>

Supongo que te gusta

Origin blog.csdn.net/www1056481167/article/details/104819762
Recomendado
Clasificación