代码之家  ›  专栏  ›  技术社区  ›  Mike Me

CSS动画位于元素下方并垂直居中

  •  0
  • Mike Me  · 技术社区  · 6 年前

    我想实现以下目标:

    • -请看我想要达到的附加图像
    • 从Y轴的角度来看,cloud1位于欢迎区的中心。

    <div class="welcome-section">
      <div id="cloud1"></div>
      <div fxLayout="column" fxLayoutAlign="center center">
        <h1 style="text-align: center;">THE BEST IS YET TO COME</h1>
        <h2 style="text-align: center;" fxFlexOffset="50px">USE IT TO DO ANYTHING</h2>
        <button mat-raised-button fxFlexOffset="25px">TRY IT FOR FREE</button>
        <img class="recycle-image" src="https://cdn2.iconfinder.com/data/icons/flat-jewels-icon-set/512/0000_Refresh.png" alt="Computer Hope" fxFlexOffset="25px">
      </div>
    </div>
    

    CSS格式:

    #cloud1{
      width:300px;
      height:100px;
      background:#cb239e;
      margin:140px 0 0 0;
      border-radius:50px;
      -webkit-transform:translateX(-400px);
      transform:translateX(-400px);
      -webkit-animation: move 7s linear infinite;
      animation: move 7s linear infinite ;
      display:block-inline;
      position: relative;
    
    }
    #cloud1:before{
      content:"";
      position: relative;
      width:180px;
      height:180px;
      background:#cb239e;
      border-radius:50%;
      margin:-100px 0 0 20px;
    
    }
    #cloud1:after{
      content:"";
      position: absolute;
      width:120px;
      height:120px;
      background:#cb239e;
      border-radius:50%;
      margin:-60px 0 0 165px;
    
    }
    

    我还做了一个 demo .

    enter image description here 任何帮助都将不胜感激。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Jignesh Sanghani    6 年前

     p {
      font-family: Lato;
    }
    
    .welcome-section {
      width: 100%;
      min-height: 400px;
      height: auto;
      background: #3f51b5;
      background-size: auto auto;
      margin-bottom: 50px;
      z-index: -1;
    }
    .welcome-section h1,
    .welcome-section h2,
    .welcome-section button,
    .welcome-section img{
      z-index: 1;
    }
    #cloud1{
      position: absolute;
      top: 25%;
      width:300px;
      height:100px;
      background:#cb239e;
      margin:140px 0 0 0;
      border-radius:50px;
      -webkit-transform:translateX(-400px);
      transform:translateX(-400px);
      -webkit-animation: move 7s linear infinite;
      animation: move 7s linear infinite ;
      display: flex;
      // overflow-x: auto;
      z-index: 0;
    }
    #cloud1:before{
      content:"";
      position: relative;
      width:180px;
      height:180px;
      background:#cb239e;
      border-radius:50%;
      margin:-100px 0 0 20px;
    
    }
    #cloud1:after{
      content:"";
      position: absolute;
      width:120px;
      height:120px;
      background:#cb239e;
      border-radius:50%;
      margin:-60px 0 0 165px;
    
    }
    
    @-webkit-keyframes move {
      0%{-webkit-transform:translateX(-340px);opacity:0;}
      20%{opacity:1;}
      90%{opacity:1;}
      100%{-webkit-transform:translateX(1650px);opacity:0;}
    }
    @keyframes move {
      0%{-webkit-transform:translateX(-340px);opacity:0;}
      20%{opacity:1;}
      90%{opacity:1;}
      100%{-webkit-transform:translateX(1650px);opacity:0;}
    }
    
    img.recycle-image {
      width: 250px;
    }