demo.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div {
width: 1000px;
height: 100px;
border: 1px solid #000;
margin: 5px auto;
}
/* 线性渐变色 */
div:nth-child(1) {
background: linear-gradient(to right, yellow, blue); /* 方向(默认从上到下),起始颜色,终止颜色 */
}
div:nth-child(2) {
background: linear-gradient(yellow, blue); /* 方向(默认从上到下) */
}
div:nth-child(3) {
width: 200px;
height: 200px;
background: linear-gradient(45deg, yellow, blue); /* 方向可以是角度 */
}
div:nth-child(4) {
background: linear-gradient(to right, yellow 0%, red 40%, green 70%,blue 100%); /* 多种颜色,百分比表示渐变线上的位置 */
}
div:nth-child(5) {
background: linear-gradient(45deg, yellow 0%, yellow 25%, red 25%, red 50%, green 50%, green 75%, blue 75%, blue 100%); /* 多种颜色,百分比表示渐变线上的位置 */
}
/* 斑马线效果 */
div:nth-child(6) {
background: linear-gradient(45deg, #000 0%, #000 25%, #fff 25%, #fff 50%, #000 50%, #000 75%, #fff 75%, #fff 100%);
/*background-repeat: no-repeat;*/ /* 默认会平铺 */
background-size: 99px 100%; /* 控制显示区域大小,然后平铺 */
}
</style>
</head>
<body>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</body>
</html>