1. 效果图
2. 代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/* 两边向中间渐变 */
.center-to-sides {
position: relative;
margin: 75px 0;
width: 100%;
height: 1px;
}
.center-to-sides:before {
content: "";
position: absolute;
background-image: linear-gradient(to right, #ff0000, transparent);
left: 10%;
right: 50%;
height: 1px;
}
.center-to-sides:after {
content: "";
position: absolute;
background-image: linear-gradient(to left, #ff0000, transparent);
left: 50%;
right: 10%;
height: 1px;
}
/* 中间向两边渐变 */
.sides-to-center {
position: relative;
margin: 75px 0;
width: 100%;
height: 1px;
}
.sides-to-center:before {
content: "";
position: absolute;
background-image: linear-gradient(to left, #ff0000, transparent);
left: 10%;
right: 50%;
height: 1px;
}
.sides-to-center:after {
content: "";
position: absolute;
background-image: linear-gradient(to right, #ff0000, transparent);
left: 50%;
right: 10%;
height: 1px;
}
</style>
</head>
<body>
<div class="center-to-sides"></div>
<div class="sides-to-center"></div>
</body>
</html>