【问题标题】:Rotate triangle with around centre point CSS围绕中心点 CSS 旋转三角形
【发布时间】:2020-06-08 21:25:27
【问题描述】:

我的项目中有这段代码:

body {
  background-color: #312a50;
  font-family: Helvetica Neue;
  color: white;
}

html,
body {
  height: 100%;
}

.main {
  height: 100%;
  width: 100%;
  display: table;
}

.wrapper {
  display: table-cell;
  height: 100%;
  vertical-align: middle;
}

.t1 {
  width: 0;
  height: 0;
  margin: auto;
  border-right: 50px solid transparent;
  border-bottom: 86.6px solid blue;
  border-left: 50px solid transparent;
}

@-webkit-keyframes rotating {
  from {
    -webkit-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes rotating {
  from {
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

.rotating {
  -webkit-animation: rotating 2s linear infinite;
  -moz-animation: rotating 2s linear infinite;
  -ms-animation: rotating 2s linear infinite;
  -o-animation: rotating 2s linear infinite;
  animation: rotating 2s linear infinite;
}
<div class="main">
  <div style="text-align: center;" class="wrapper">
    <div class="t1 rotating"></div>
  </div>
</div>

我的三角形目前可以正常旋转,并且速度合适,但它没有在三角形的中心点旋转。它似乎从稍微偏离中心的一点旋转。

另外,如何只显示三角形的边框而不显示完整的纯蓝色?

任何帮助将不胜感激!

谢谢!

【问题讨论】:

    标签: html css


    【解决方案1】:

    你需要将transform-origin调整为50% 66%

    body {
      background-color: #312a50;
      font-family: Helvetica Neue;
      color: white;
    }
    
    html,
    body {
      height: 100%;
    }
    
    .main {
      height: 100%;
      width: 100%;
      display: table;
    }
    
    .wrapper {
      display: table-cell;
      height: 100%;
      vertical-align: middle;
    }
    
    .t1 {
      width: 0;
      height: 0;
      margin: auto;
      border-right: 50px solid transparent;
      border-bottom: 86.6px solid blue;
      border-left: 50px solid transparent;
      transform-origin: 50% 66%;
    }
    
    
    @keyframes rotating {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }
    
    .rotating {
      animation: rotating 2s linear infinite;
    }
    <div class="main">
      <div style="text-align: center;" class="wrapper">
        <div class="t1 rotating"></div>
      </div>
    </div>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 2012-04-08
    • 2023-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多