css - less.js 是否编译浏览器兼容的 css 代码?

标签 css less

有没有一种方法可以在 less 中轻松地将 less 代码编译为以下浏览器兼容的 css 代码?

#grad1 {
    background: -webkit-linear-gradient(red, blue); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(red, blue); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(red, blue); /* For Firefox 3.6 to 15 */
    background: linear-gradient(red, blue); /* Standard syntax (must be last) */
}

还是我必须手动完成?

另外我意识到我的 less 代码没有按字母顺序编译,我正在使用以下命令行 lessc (less file) (css file)

最佳答案

是的,你可以创建 mixins 来做你想做的事:

.grad1() {
    background: -webkit-linear-gradient(red, blue); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(red, blue); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(red, blue); /* For Firefox 3.6 to 15 */
    background: linear-gradient(red, blue); /* Standard syntax (must be last) */
}

然后在要添加此背景的地方调用它:

.class-with-grad1 {
    .grad1();
    /** other less/css stuff **/
}

一旦你的 less 被编译,你将得到:

.class-with-grad1 {
    background: -webkit-linear-gradient(red, blue);
    background: -o-linear-gradient(red, blue);
    background: -moz-linear-gradient(red, blue);
    background: linear-gradient(red, blue);
    /** other less/css stuff **/
}

Documentation for less mixins

关于css - less.js 是否编译浏览器兼容的 css 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33270998/

相关文章:

javascript - 隐藏在 Firefox 中的滚动条

javascript - 在脚本中设置图标样式?

css - Less css 中的嵌套伪类

css - LESS Mixin for 循环

html - 跨度、输入、跨度 100% 宽度 CSS 问题

css - 垂直对齐多行文本?

css - Mozilla 和其他人之间的 Div Padding 差异

html - 如何使用伪选择器仅使用 CSS 将 "Home"按钮更改为图标?

css - 如何使用 .less 在按钮上组合类?

html - 仅使用 CSS 使相邻的兄弟元素具有相同的宽度