background linear gradient
背景颜色渐变
HTML
<div class="linear-color">linear color change</div>
CSS
.linear-color{
width: 300px;
height: 200px;
color: #fff;
}
/* 渐变效果 type1 */
/*
.linear-color{
background: olive linear-gradient(to right, rgba(0,255,0,0), rgba(0,255,0,.5));
transition: all .5s;
}
.linear-color:hover{
background-color: purple;
}
*/
/* 渐变效果 type2 */
/*
.linear-color{
background: linear-gradient(to right, olive, green);
position: relative;
z-index: 0;
}
.linear-color::before{
content: '';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: linear-gradient(to right, green, purple);
opacity: 0;
transition: all .5s;
z-index: -1;
}
.linear-color:hover::before{
opacity: 1;
}
*/
/* 渐变效果 type3 */
.linear-color{
background: linear-gradient(to right, olive, green, purple);
background-size: 200%;
transition: all .5s;
}
.linear-color:hover{
background-position: 100%;
}