我刚刚开始PHP开发。我屏幕上有多个文本,我想在文本翻转后将文本置于屏幕中心。我先尝试谷歌,所以我得到了CSS代码。由于我是新人,所以无法使其发挥作用。
如果问题有误,请告诉我我可以删除它。
提前致谢。
我的代码可以更详细地向您解释。
/*Vertical Flip*/
.verticalFlip{
display: inline;
text-indent: 8px;
}
.verticalFlip span{
animation: vertical 12.5s linear infinite 0s;
-ms-animation: vertical 12.5s linear infinite 0s;
-webkit-animation: vertical 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
overflow: hidden;
position: absolute;
}
.verticalFlip span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.verticalFlip span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
.verticalFlip span:nth-child(4){
animation-delay: 7.5s;
-ms-animation-delay: 7.5s;
-webkit-animation-delay: 7.5s;
}
.verticalFlip span:nth-child(5){
animation-delay: 10s;
-ms-animation-delay: 10s;
-webkit-animation-delay: 10s;
}
/*Vertical Flip Animation*/
@-moz-keyframes vertical{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: rotateX(180deg); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0;}
}
@-webkit-keyframes vertical{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: rotateX(180deg); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@-ms-keyframes vertical{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: rotateX(180deg); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
.bgimg{
position: relative;
text-align: center;
color: white;
}
.imgcentered {
width: 100%;
position: absolute;
/*top: 50%;
left: 40%;
transform: translate(-50%, -50%);*/
}
.sentence{
font-size: 75px;
color: black;
text-transform: uppercase;
}
<div class="bgimg">
<div class="imgcentered">
<h2 class="sentence">WE ARE<div class="verticalFlip">
<span>INDIAN</span>
<span>Perfection</span>
<span>Trustworthy</span>
<span>Responsive</span>
<span>Supportive</span>
</div>
</h2>
</div>
</div>
最佳答案
您的问题与盒子模型有关。显示这些文字的方式是淡入淡出不透明度,但它们仍然占用空间。因此,您已将其位置设置为绝对
。当它是绝对的时,它不能向框添加任何额外的宽度,因此 CSS 的默认居中将不起作用。但是,如果您将绝对值关闭,则无法让它们全部重叠在一起,因为您无法在其上设置 display: none
动画。
我建议取消 position:absolute
并且不要依赖 CSS 来进行延迟/计时。相反,添加一些带有 setInterval
的简单 JS,它将在每个时间间隔上将一个类(例如 active
)添加到列表中的下一个范围,从列表中删除该类其他的。然后在非事件的元素上设置 display none ,在事件的元素上设置 display: inline-block
。
无论哪种方式,您都需要使用 JavaScript 动态设置左侧位置,或者使用 JavaScript 进行循环。我不相信有一种方法可以只用纯 CSS 来做到这一点。
关于javascript - 自动垂直翻转后的文本居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419254/