我刚开始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>
&#13;
答案 0 :(得分:0)
您的问题与盒子模型有关。你展示这些单词的方式是通过淡入淡出不透明的方式,但它们仍占用空间。因此,您已将自己的位置设置为absolute
。如果它是绝对的,它就不能在框中添加任何额外的宽度,因此CSS的默认居中不会起作用。但是,如果你采取绝对禁用,那么就无法将它们全部放在一起,因为你无法在display: none
上进行动画制作。
我建议取消position: absolute
而不是依赖CSS来做延迟/计时。而是添加一些带有setInterval
的简单JS,它将在每个时间间隔上将一个类(例如active
)添加到列表中的下一个范围,从而将类从其他范围中删除。然后在非活动的那些上设置display none,在活动的那个上设置display: inline-block
。
无论哪种方式,您都需要使用javascript动态设置左侧位置,或使用javascript进行循环。我不相信只有纯CSS才能做到这一点。
答案 1 :(得分:0)
/*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;
}
.verticalFlip span:nth-child(6){
animation-delay: 12.5s;
-ms-animation-delay: 12.5s;
-webkit-animation-delay: 12.5s;
}
.verticalFlip span:nth-child(7){
animation-delay: 15s;
-ms-animation-delay: 15s;
-webkit-animation-delay: 15s;
}
/*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>
<span>Responsive</span>
<span>Supportive</span>
</div>
</h2>
</div>
</div>