Jos*_*ier 30
有多种不同的方法可以实现这一目标.
<div class="progress"></div>
Run Code Online (Sandbox Code Playgroud)
.progress {
width:200px;
height:50px;
border:1px solid black;
position:relative;
}
.progress:after {
content:'\A';
position:absolute;
background:black;
top:0; bottom:0;
left:0;
width:50%; /* Specify the width.. */
}
Run Code Online (Sandbox Code Playgroud)
这种方法的优点是你可以指定多种不同的颜色..
.progress {
width:200px;
height:50px;
border:1px solid black;
background: -webkit-linear-gradient(left, black 50%, white 50%);
background: -moz-linear-gradient(left, black 50%, white 50%);
background: -ms-linear-gradient(left, black 50%, white 50%);
background: linear-gradient(left, black 50%, white 50%);
}
Run Code Online (Sandbox Code Playgroud)
这些方法中的任何一种都可以使用纯CSS进行动画处理.
.progress:after {
/* other styling .. */
width:50%; /* End width.. */
-webkit-animation: filler 2s ease-in-out;
-moz-animation: filler 2s ease-in-out;
animation: filler 2s ease-in-out;
}
@-webkit-keyframes filler {
0% {
width:0;
}
}
Run Code Online (Sandbox Code Playgroud)
.progress:after {
/* other styling.. */
width:0;
transition:all 2s;
-webkit-transition:all 2s;
}
.progress:hover:after {
width:50%;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
是的,通过使用渐变止挡,即使是一格也可以实现;
的HTML
<div></div>
Run Code Online (Sandbox Code Playgroud)
的CSS
div {
width:400px;
height:400px;
background: -webkit-linear-gradient(left, #00ff00 50%, #ff0000 50%);
background: -moz-linear-gradient(left, #00ff00 50%, #ff0000 50%);
background: -o-linear-gradient(left, #00ff00 50%, #ff0000 50%);
background: -ms-linear-gradient(left, #00ff00 50%, #ff0000 50%);
background: linear-gradient(left, #00ff00 50%, #ff0000 50%);
}
Run Code Online (Sandbox Code Playgroud)