代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>公告</title>
<style>
.marquee {
width: 450px;
margin: 0 auto;
overflow: hidden;
white-space: nowrap;
box-sizing: border-box;
animation: marquee 50s linear infinite;
}
.marquee:hover {
animation-play-state: paused
}
/* 使段落文字滚动 */
@keyframes marquee {
0% { text-indent: 27.5em }
100% { text-indent: -105em }
}
/* 滚动文字前加图片 */
.microsoft {
padding-left: 1.5em;
position: relative;
font: 16px 'Segoe UI', Tahoma, Helvetica, Sans-Serif;
}
.microsoft:before{
z-index: 2;
content: '';
position: absolute;
top: -1em; left: -1em;
width: .5em; height: .5em;
}
.microsoft:after, .microsoft::after {
z-index: 1;
content: '';
position: absolute;
top: -4px; left: 0;
width: 2em; height: 2em;background-color:white;
background-size: 100%;
background-image:url(./img/laba.png);
/* background-image: linear-gradient(90deg, white 70%, rgba(255,255,255,0));*/
}
</style>
</head>
<body>
<p class="microsoft marquee">公告:测试公告信息,测试公告信息,测试公告信息,测试公告信息</p>
</body>
</html>
效果: