HTML代码:
<html>
<head>
<title>CSS3让字一个一个出现的效果</title>
<style>
.text{
font-size: 30px;
color: #FFB6C1;
width: 0;
white-space: nowrap;
overflow: hidden;
animation: type 2s steps(22,end);
animation-delay: 1s;
animation-fill-mode: forwards;
}
@keyframes type{
from{width: 0;}
to{width: 660px;}
}
</style>
</head>
<body>
<p class="text">
CSS3能够为网页添加各种效果,其中一个非常实用的效果就是让字一个一个地出现。这种效果可以让网页更有吸引力,同时也能够更好地吸引用户的注意力。
</p>
</body>
</html> .text{
font-size: 30px;
color: #FFB6C1;
width: 0;
white-space: nowrap;
overflow: hidden;
animation: type 2s steps(22,end);
animation-delay: 1s;
animation-fill-mode: forwards;
}
@keyframes type{
from{width: 0;}
to{width: 660px;}
} .text{
font-size: 30px; /*字体大小*/
color: #FFB6C1; /*字体颜色*/
width: 0; /*初始宽度为0*/
white-space: nowrap; /*让字不换行*/
overflow: hidden; /*隐藏溢出的部分*/
animation: type 2s steps(22,end); /*指定动画名称、持续时间、步长等参数*/
animation-delay: 1s; /*指定动画延迟1秒开始*/
animation-fill-mode: forwards; /*将动画最终状态保留在元素上,避免出现突兀的效果*/
} @keyframes type{
from{width: 0;} /*初始宽度为0*/
to{width: 660px;} /*最终宽度为文字的总宽度*/
}