Is there a CSS tool / language / syntax to simplify "-moz" "-webkit" "-ms" "-o" statements compatibility?

huangapple go评论60阅读模式
英文:

Is there a CSS tool / language / syntax to simplify "-moz" "-webkit" "-ms" "-o" statements compatibility?

问题

这是一个具有许多兼容性版本的示例代码:

.shake {
  background-color: #2bd993;
  color: #fff;
  font-size: 24px;
  margin: 30px 0 0;
  padding: 20px;
  text-transform: uppercase;
}

.shake:hover {
  animation: shake 150ms 2 linear;
  -moz-animation: shake 150ms 2 linear;
  -webkit-animation: shake 150ms 2 linear;
  -o-animation: shake 150ms 2 linear;
}

@keyframes shake {
  0% {
    transform: translate(3px, 0);
  }
  50% {
    transform: translate(-3px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}

@-moz-keyframes shake {
  0% {
    -moz-transform: translate(3px, 0);
  }
  50% {
    -moz-transform: translate(-3px, 0);
  }
  100% {
    -moz-transform: translate(0, 0);
  }
}

@-webkit-keyframes shake {
  0% {
    -webkit-transform: translate(3px, 0);
  }
  50% {
    -webkit-transform: translate(-3px, 0);
  }
  100% {
    -webkit-transform: translate(0, 0);
  }
}

@-ms-keyframes shake {
  0% {
    -ms-transform: translate(3px, 0);
  }
  50% {
    -ms-transform: translate(-3px, 0);
  }
  100% {
    -ms-transform: translate(0, 0);
  }
}

@-o-keyframes shake {
  0% {
    -o-transform: translate(3px, 0);
  }
  50% {
    -o-transform: translate(-3px, 0);
  }
  100% {
    -o-transform: translate(0, 0);
  }
}

是否有CSS语言/语法/编写更少代码同时最大化向后兼容性的技巧?

到目前为止,我所取得的最好成果是使用CSS变量,但我想知道是否可以进一步简化。

英文:

This is an example code with many compatibility versions:

.shake {
background-color: #2bd993;
color: #fff;
font-size: 24px;
margin: 30px 0 0;
padding: 20px;
text-transform: uppercase;
}
.shake:hover {
animation: shake 150ms 2 linear;
-moz-animation: shake 150ms 2 linear;
-webkit-animation: shake 150ms 2 linear;
-o-animation: shake 150ms 2 linear;
}
@keyframes shake {
0% {
transform: translate(3px, 0);
}
50% {
transform: translate(-3px, 0);
}
100% {
transform: translate(0, 0);
}
}
@-moz-keyframes shake {
0% {
-moz-transform: translate(3px, 0);
}
50% {
-moz-transform: translate(-3px, 0);
}
100% {
-moz-transform: translate(0, 0);
}
}
@-webkit-keyframes shake {
0% {
-webkit-transform: translate(3px, 0);
}
50% {
-webkit-transform: translate(-3px, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
@-ms-keyframes shake {
0% {
-ms-transform: translate(3px, 0);
}
50% {
-ms-transform: translate(-3px, 0);
}
100% {
-ms-transform: translate(0, 0);
}
}
@-o-keyframes shake {
0% {
-o-transform: translate(3px, 0);
}
50% {
-o-transform: translate(-3px, 0);
}
100% {
-o-transform: translate(0, 0);
}
}

Are there CSS languages / syntax / tips to write less code while maximizing retrocompatibility ?

The best I have achieved so far was with the use of CSS variables, but I wonder if we can simplify further.

答案1

得分: 1

如果您使用SASS或类似工具,可以添加Autoprefixer,您还可以查看https://caniuse.com/,看看是否仍然需要添加前缀。

英文:

If you would use SASS or the like you could add an Autoprefixer, you can also check https://caniuse.com/ and see if it is still necessary to add the prefixes

huangapple
  • 本文由 发表于 2023年4月20日 06:28:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定