html - Sass 和关键帧

标签 html css sass css-animations prepros

我正在尝试使用 css 关键帧创建一个旋转的圆圈,但我在尝试让它在 Sass 中工作时遇到了困难。

这是我的 html:

<div class="content">
    <h1 class="h1">Playing around with keyframes</h1>
    <div class="circle"></div>
</div>

这是 Sass:

.content{
        display:block;
        position: relative;
        box-sizing:border-box;

        .circle{
            width: 220px;
            height: 220px;
            border-radius: 50%;
            padding: 10px;
            border-top: 2px solid $pink;
            border-right: 2px solid $pink;
            border-bottom: 2px solid $pink;
            border-left: 2px solid #fff;
            -webkit-animation:spin 4s linear infinite;
            -moz-animation:spin 4s linear infinite;
            animation:spin 4s linear infinite;
        }

        @-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
        @-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
        @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
    }

我正在使用 Prepros 编译我的 Sass,输出如下所示(注意关键帧内的类):

@-moz-keyframes spin {
  .lesson-page .content 100%  {
    -moz-transform: rotate(360deg);
  }
}
@-webkit-keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
  }
}
@keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

最佳答案

这似乎是 Sass 3.3 特有的。 @keyframes 构造没有正确地冒泡到顶部。如果无法升级到 3.4,只需停止嵌套关键帧即可。

.content{
    display:block;
    position: relative;
    box-sizing:border-box;

    .circle{
        width: 220px;
        height: 220px;
        border-radius: 50%;
        padding: 10px;
        border-top: 2px solid $pink;
        border-right: 2px solid $pink;
        border-bottom: 2px solid $pink;
        border-left: 2px solid #fff;
        -webkit-animation:spin 4s linear infinite;
        -moz-animation:spin 4s linear infinite;
        animation:spin 4s linear infinite;
    }
}

@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }

相关:How to make a Sass mixin declare a non-nested selector on base level?

关于html - Sass 和关键帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26164379/

相关文章:

javascript - 单击更改事件菜单项的字体

jquery - 溢出时如何使文本变小

css - 如何正确覆盖 Angular 库的变量

sass - 无法使用 grunt-autoprefixer 获取 Sass Source Maps

sass - WebStorm 中的未知伪选择器 'export'

html - Materialise grid 做5列

html - 前导点的 CSS 样式

javascript - onclick,更改类并重置其他类

Javascript [数据标签] 在 Firefox 中工作,而不是在 Chrome 中工作

html - IE 中的背景图片