【问题标题】:Text in the CSS slide overlapsCSS 幻灯片中的文本重叠
【发布时间】:2021-07-14 16:50:35
【问题描述】:

我正在尝试使用 css 在幻灯片中插入 4 行文本。效果有效,但是当它到达第三张和第四张幻灯片时,文本重叠并且不会在正确的时间改变。

我该如何纠正这个问题?

这是我的代码:

.col-sm-12{width:100%;padding:15px;float:left;}

#textComAz .item-1, #textComAz .item-2, #textComAz .item-3, #textComAz .item-4 {position: absolute;display: block;top: 2em;width: 100%;font-size: 2em;animation-duration: 20s;animation-timing-function: ease-in-out;animation-iteration-count: infinite;text-align:center;}
#textComAz .item-1{animation-name: anim-1;}
#textComAz .item-2{animation-name: anim-2;}
#textComAz .item-3{animation-name: anim-3;}
#textComAz .item-4{animation-name: anim-4;}

@keyframes anim-1 {0%, 8.3% { left: -50%; opacity: 0; }8.3%,25% { left: 0%; opacity: 1; }33.33%, 100% { left: 25%; opacity: 0; }}

@keyframes anim-2 {0%, 33.33% { left: -50%; opacity: 0; }41.63%, 58.29% { left: 0%; opacity: 1; }66.66%, 100% { left: 25%; opacity: 0; }}

@keyframes anim-3 {0%, 55.55% { left: -50%; opacity: 0; }64.96%, 71.62% { left: 0%; opacity: 1; } 100% { left: 25%; opacity: 0; }}

@keyframes anim-4 {0%, 75.55% { left: -50%; opacity: 0; }84.96%, 91.62% { left: 0%; opacity: 1; }100% { left: 25%; opacity: 0; }}
<div id="textComAz" class="col-sm-12">
<p class="item-1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.</p>
<p class="item-2">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.</p>
<p class="item-3">But I must explain to you how all this mistaken idea of denouncing pleasure.</p>

<p class="item-4">NEW TEXT HERE.</p>
</div>

【问题讨论】:

    标签: html css animation


    【解决方案1】:

    您需要将% 更改为关键帧以呈现您需要的结果,我只需更改一点% 但您需要为您的结果更改它。

    .col-sm-12 {
      width: 100%;
      padding: 15px;
      float: left;
    }
    
    #textComAz .item-1,
    #textComAz .item-2,
    #textComAz .item-3,
    #textComAz .item-4 {
      position: absolute;
      display: block;
      top: 2em;
      width: 100%;
      font-size: 2em;
      animation-duration: 20s;
      animation-timing-function: ease-in-out;
      animation-iteration-count: infinite;
      text-align: center;
    }
    
    #textComAz .item-1 {
      animation-name: anim-1;
    }
    
    #textComAz .item-2 {
      animation-name: anim-2;
    }
    
    #textComAz .item-3 {
      animation-name: anim-3;
    }
    
    #textComAz .item-4 {
      animation-name: anim-4;
    }
    
    @keyframes anim-1 {
      0%,
      8.3% {
        left: -50%;
        opacity: 0;
      }
      8.3%,
      25% {
        left: 0%;
        opacity: 1;
      }
      33.33%,
      100% {
        left: 25%;
        opacity: 0;
      }
    }
    
    @keyframes anim-2 {
      0%,
      33.33% {
        left: -50%;
        opacity: 0;
      }
      41.63%,
      58.29% {
        left: 0%;
        opacity: 1;
      }
      66.66%,
      100% {
        left: 25%;
        opacity: 0;
      }
    }
    
    @keyframes anim-3 {
      0%,
       66.66% {
        left: -50%;
        opacity: 0;
      }
      74.96%,
      83.26% {
        left: 0%;
        opacity: 1;
      }
      83.26%,
      100% {
        left: 25%;
        opacity: 0;
      }
    }
    
    @keyframes anim-4 {
      0%,
      83.26% {
        left: -50%;
        opacity: 0;
      }
      91.56%,
      99.86% {
        left: 0%;
        opacity: 1;
      }
      100% {
        left: 25%;
        opacity: 0;
      }
    }
    <div id="textComAz" class="col-sm-12">
      <p class="item-1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.</p>
      <p class="item-2">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.</p>
      <p class="item-3">But I must explain to you how all this mistaken idea of denouncing pleasure.</p>
    
      <p class="item-4">NEW TEXT HERE.</p>
    </div>

    你可以阅读:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-04
      • 2013-04-29
      • 1970-01-01
      • 2015-12-19
      相关资源
      最近更新 更多