标签文本居中摆动可以通过CSS动画来实现。下面是一种实现方式:
HTML代码:
<div class="container">
<span class="text">标签文本</span>
</div>
CSS代码:
.container {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
border: 1px solid #ccc;
}
.text {
animation: swing 2s infinite;
}
@keyframes swing {
0% {
transform: translateX(0);
}
50% {
transform: translateX(10px);
}
100% {
transform: translateX(0);
}
}
解释:
<div class="container">
),设置其为flex布局,并使用justify-content: center;
和align-items: center;
使文本水平和垂直居中。<span>
元素,用于显示标签文本。animation
属性给文本添加一个名为swing
的动画,持续时间为2秒,无限循环播放。@keyframes
中定义动画的关键帧:这样,标签文本就会在容器内居中摆动。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云