效果1
效果1实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,p{
margin: 0;
padding: 0;
}
.box{
width: 500px;
height: 300px;
border: 5px solid blue;
margin: 30px;
overflow: hidden;
}
.bigbox{
width: 2500px;
height: 300px;
background: yellow;
animation: move 5s infinite steps(5);
}
.bigbox p{
width: 500px;
height: 300px;
float: left;
font-size: 80px;
text-align: center;
line-height: 300px;
}
p:nth-child(1){
background: red;
}
p:nth-child(2){
background: rgb(94, 255, 0);
}
p:nth-child(3){
background: rgb(0, 68, 255);
}
p:nth-child(4){
background: rgb(255, 0, 191);
}
p:nth-child(5){
background: rgb(255, 251, 0);
}
@keyframes move{
0%{
margin-left: 0;
}
100%{
margin-left: -2500px;
}
}
</style>
</head>
<body>
<div class="box">
<div class="bigbox">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
</div>
</div>
</body>
</html>
效果2
宽度占满浏览器,随浏览器的缩放而缩放
效果2实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,p{
margin: 0;
padding: 0;
}
.box{
width: 100%;
height: 300px;
overflow: hidden;
}
.bigbox{
width: 500%;
/* 这里的500%是指box盒子的5倍 */
height: 300px;
background: yellow;
animation: move 5s infinite steps(5);
}
.bigbox p{
width: 20%;
/* 这里的20%是指bigbox盒子的五分之一 */
height: 300px;
float: left;
font-size: 80px;
text-align: center;
line-height: 300px;
}
p:nth-child(1){
background: red;
}
p:nth-child(2){
background: rgb(94, 255, 0);
}
p:nth-child(3){
background: rgb(0, 68, 255);
}
p:nth-child(4){
background: rgb(255, 0, 191);
}
p:nth-child(5){
background: rgb(255, 251, 0);
}
@keyframes move{
0%{
margin-left: 0;
}
100%{
margin-left: -500%;
}
}
/* 百分比是一个相对于最近父元素的单位 */
</style>
</head>
<body>
<div class="box">
<div class="bigbox">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
</div>
</div>
</body>
</html>