昔のマーキーみたいに文字がスクロールするコードです。
See the Pen CSSで横に流れる文字 by hiro (@hirochanpon) on CodePen.
HTML
<div class="marquee-container">
<ul class="scroll-list">
<li>Hello World!</li>
<li>Hello World!</li>
<li>Hello World!</li>
<li>Hello World!</li>
<li>Hello World!</li>
<li>Hello World!</li>
</ul>
</div>
CSS
/* 外側の枠:画面いっぱいに表示 */
.marquee-container {
width: 100%;
overflow: hidden;
background-color: #fefefe;
}
/* ulタグ:アニメーションをこちらに持たせる */
.scroll-list {
display: flex;
list-style: none;
padding: 0;
margin: 0;
width: max-content; /* 中身の幅に合わせる */
animation: marquee-left 10s linear infinite;
}
/* liタグ */
.scroll-list li {
color: #fe2c25;
font-size: 2.5em;
font-weight: bold;
white-space: nowrap;
padding-right: 2em; /* 文字の間の余白 */
margin: 0;
}
/* PCの時のフォントサイズ */
@media (min-width: 600px) {
.scroll-list li {
font-size: 3vw;
}
}
/* アニメーション:全体の半分(複製した分)まで行ったら戻る */
@keyframes marquee-left {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-50%);
}
}
昔の、<marquee>~</marquee>が懐かしいですね。
homepageで電車を走らせてました。
