其他分享
首页 > 其他分享> > CSS中RGBA和渐变色

CSS中RGBA和渐变色

作者:互联网

颜色值RGBA

我们熟悉的rgb颜色标准,是由r(red)、g(green)、b(blue)三种颜色叠加变化形成各种颜色
取值0-255,或0-100%
rgba就是在rgb基础上增加了alpha不透明度参数 

.demo {
    width: 100px;
    height: 100px;
    background-color: rgb(255, 0, 0);
}

.demo {
    width: 100px;
    height: 100px;
    background-color: rgba(255, 0, 0, 0.5);
}

 ff

alpha取值0~1,值越小越透明
#线性渐变linear-gradient#
gradient是“倾斜度”的意思,linear是“线性的”的意思
渐变色就是在多个颜色间平稳过渡,形成绚丽的色彩
线性渐变linear-gradient参数有渐变的方向(选填)和任意个渐变色 

.demo {
    width: 100px;
    height: 100px;
    background: linear-gradient(red,lime,blue);
}

注意我这里写的是background不是background-color
(其实渐变色是background-image的函数)

                                                     

 不填写渐变方向默认是从上到下
渐变方向有以下属性值
to top、to bottom(默认)、to left、to right
to top left、to top right、to bottom left、to bottom right
或者填写角度 xxxdeg
比如to top left就代表方向朝向左上

.demo {
    width: 100px;
    height: 100px;
    background: linear-gradient(to top left,red,lime,blue);
}

                                                    

 角度0deg与to top等价,增加角度,相当于顺时针旋转

.demo {
    width: 100px;
    height: 100px;
    background: linear-gradient(20deg,red,lime,blue);
}

                                                   

 在每一个颜色的后面可以添加各个颜色渐变的位置

.demo {
    width: 100px;
    height: 100px;
    background: linear-gradient(red 30%,lime 50%,blue 70%);
}

                                                 

 还有一个不常见的函数repeating-linear-gradient使我们可以重复线性渐变

.demo {
    width: 100px;
    height: 100px;
    background: repeating-linear-gradient(red, rgba(100,100,100,0.5),blue 50%);
}

                                               

 #径向渐变radial-gradient#
radial意思是“径向的、辐射状的”
就是一个渐变中心向外放射渐变

.demo {
    width: 200px;
    height: 100px;
    background: radial-gradient(red,lime,blue);
}

                                   

标签:background,gradient,渐变色,渐变,100px,height,RGBA,CSS,linear
来源: https://blog.csdn.net/m0_48982503/article/details/119766223