【发布时间】:2014-12-22 12:34:06
【问题描述】:
我通常写 SASS,但对于特定项目我必须使用 LESS。
如何使用 less 实现类似以下的效果?使用 sass 可以像 @include align(hcenter top) 一样调用 mixin 来将元素水平定位在中间和顶部。
@mixin align($styles) {
position: absolute;
content: '';
display: block;
@each $style in $styles {
@if ($style == center) {
margin-left: auto;
margin-right: auto;
margin-top: auto;
margin-bottom: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
@if ($style == hcenter) {
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
@if ($style == vcenter) {
margin-top: auto;
margin-bottom: auto;
top: 0;
bottom: 0;
}
@if ($style == top) {
top: 0;
}
@if ($style == bottom) {
bottom: 0;
}
@if ($style == right) {
right: 0;
}
@if ($style == left) {
left: 0;
}
}
}
【问题讨论】:
-
上一个是用于 SASS 到 Less 的转换。参考this在Less中循环。