4-关于 css 中透明的解析

作者: _panda | 来源:发表于2018-01-22 14:24 被阅读25次

想法 : 做一个背景透明 文字不透明的设计

方法 一 :

使用opacity后整个模块都透明了,展现如下:

那么使用opacity实现《背景透明,文字不透明》是不可取的。

image

方法 二 :

使用 rgba 来设置 background-color

background-color:rgba(0,0,0,0.2); 
/* IE6和部分IE7内核的浏览器(如QQ浏览器)会读懂,但解析为透明 */

demo : 主要使用 绝对定位 和 RGBA 来实现

.demo2-bg{
    background: url(http://csssecrets.io/images/tiger.jpg) no-repeat;
    background-size: cover;
    width: 500px;
    height: 300px;
    position: relative;
}
.demo2{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 500px;
    height: 300px;
    line-height: 50px;
    text-align: center;
    background:rgba(255,255,255,0.3);
}
<div class="demo2-bg">
    <div class="demo2">背景图半透明,文字不透明<br />方法:定位+ background:rgba(255,255,255,0.3)</div>
</div>
image

相关文章

网友评论

    本文标题:4-关于 css 中透明的解析

    本文链接:https://www.haomeiwen.com/subject/cgmlaxtx.html