演示代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
[class^="password_strength"] {
height: 4px;
background-color: #ddd;
margin-top: 5px;
width: 200px;
border-radius: 5px;
position: relative;
overflow: hidden;
}
[class^="password_strength"]::before {
content: "";
position: absolute;
width: 0;
height: 100%;
transition:all 0.3s;
}
.password_strength1::before {
width: 20%;
background-color: #ff5722;
}
.password_strength2::before {
width: 40%;
background-color: #ff5722;
}
.password_strength3::before {
width: 60%;
background-color: #ffb82f;
}
.password_strength4::before {
width: 80%;
background-color: #5fb878;
}
.password_strength5::before {
width: 100%;
background-color: #5fb878;
}
[class^="password_strength"]::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
to right,
transparent 0%,
transparent 18%,
#fff 18%,
#fff 20.5%
);
}
</style>
</head>
<body>
<div class="password_strength0"></div>
<div class="password_strength1"></div>
<div class="password_strength2"></div>
<div class="password_strength3"></div>
<div class="password_strength4"></div>
<div class="password_strength5"></div>
</body>
</html>
纯净样式
[class^="password_strength"] {
height: 4px;
background-color: #ddd;
margin-top: 5px;
width: 200px;
border-radius: 5px;
position: relative;
overflow: hidden;
}
[class^="password_strength"]::before {
content: "";
position: absolute;
width: 0;
height: 100%;
transition:all 0.3s;
}
.password_strength1::before {
width: 20%;
background-color: #ff5722;
}
.password_strength2::before {
width: 40%;
background-color: #ff5722;
}
.password_strength3::before {
width: 60%;
background-color: #ffb82f;
}
.password_strength4::before {
width: 80%;
background-color: #5fb878;
}
.password_strength5::before {
width: 100%;
background-color: #5fb878;
}
[class^="password_strength"]::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
to right,
transparent 0%,
transparent 18%,
#fff 18%,
#fff 20.5%
);
}
使用方法
<div class="password_strength0"></div>
<div class="password_strength1"></div>
<div class="password_strength2"></div>
<div class="password_strength3"></div>
<div class="password_strength4"></div>
<div class="password_strength5"></div>
<!-- password_strength为基础样式,可在后方跟数字0-5显示不同样式 -->
效果
