纯css实现文字走马灯
主要用到了css3中animation,效果和代码如下
![在这里插入图片描述](https://img-blog.csdnimg.cn/e14aa8045a0e46ab839e48d20c2d8633.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiA5p2v5YWF5ruh5rOh5rOh55qE5Y-v5LmQ,size_8,color_FFFFFF,t_70,g_se,x_16)
<!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>
* {
margin: 0;
padding: 0;
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
user-select: none;
-webkit-user-select: none;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
}
.wrap .info {
height: 20px;
margin: 10px;
font-size: 14px;
color: white;
padding: 0 5px;
background-color: black;
display: flex;
align-items: center;
border-radius: 4px;
}
.wrap .info .words-inner {
white-space: nowrap;
overflow: hidden;
margin: 0 0 0 5px;
}
.wrap .info .words-inner .words {
position: relative;
width: fit-content;
animation: move 8s linear infinite;
}
.wrap .info .words-inner .words::after {
position: absolute;
right: -100%;
content: attr(text);
}
@keyframes move {
0% {
transform: translateX(5%);
}
100% {
transform: translateX(-100%);
}
}
.wrap .info img {
width: 10px;
height: 10px;
object-fit: cover;
}
</style>
</head>
<body>
<div class="wrap">
<div class="info">
<!-- 图片可以自定义 -->
<img src="./images/top-one.png" alt="">:
<div class="words-inner">
<p class="words">
测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试结束
</p>
</div>
</div>
</div>
</body>
</html>```