twitter-bootstrap - Bootstrap 3 翻译混入

标签 twitter-bootstrap css less less-mixins

如何在 translate mixin 上添加值?我想在 Y 坐标上有这些值:

-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);

Bootstrap 混合:

.translate(@x; @y) {
-webkit-transform: translate(@x, @y);
  -ms-transform: translate(@x, @y); // IE9 only
   -o-transform: translate(@x, @y);
      transform: translate(@x, @y);
}

如何在 Y 坐标上添加 50%??? 我试过:

.translate(@y: 50%);

但是我得到一个错误,有什么想法吗???

最佳答案

Note: Using Less mixins for vendor prefixing is not good practice and this answer does not make any attempts to recommend it. It only provides a straight answer to the question that was asked. If you are interested in knowing the recommended approach for vendor prefixing, have a loot at Bass Jobsen's answer in this thread.

为什么你的 mixin 调用不起作用?

每当进行 mixin 调用时,如果所有参数都有值(默认值或在 mixin 调用中传递的值),Less 只会调用 mixin。

在这种情况下, Bootstrap translate mixin 有 2 个参数(没有默认值),而 mixin 调用只有一个参数。因此,mixin 永远不会被调用/处理。


问题的解决方案是什么?

为了克服这个问题,您可以将 0(或 0%)传递给 @x 参数,例如

.translate(@x; @y) {
  -webkit-transform: translate(@x, @y);
  -ms-transform: translate(@x, @y); // IE9 only
  -o-transform: translate(@x, @y);
  transform: translate(@x, @y);
}

div{
  .translate(@x: 0%;@y: 50%);
}

这将产生一个基本上等同于仅在 Y 轴上进行平移的输出(如 this simple sample 中所示)。

下面是输出

div {
  -webkit-transform: translate(0%, 50%);
  -ms-transform: translate(0%, 50%);
  -o-transform: translate(0%, 50%);
  transform: translate(0%, 50%);
}

相当于

div {
  -webkit-transform: translateY(50%);
  -ms-transform: translateY(50%);
  -o-transform: translateY(50%);
  transform: translateY(50%);
}

关于twitter-bootstrap - Bootstrap 3 翻译混入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27939590/

相关文章:

jquery - Kendo 自动完成如何禁用默认的 css 样式

CSS 叠加效果 - 排除某些容器

css-float - 如何使 float 元素居中?

css - 更少的继承和层次结构,有什么问题?

javascript - Jquery 函数在错误时间提交

css - 带下拉菜单的 Bootstrap 面板选项卡

twitter-bootstrap - 带 Bootstrap react 的全高列

html - 在 Bootstrap 中更改轮播的标题文本的大小

css - 如何在 LESS CSS 1.4+ 中覆盖 mixins

css - 在具有 FIXED 布局的 Semantic.gs 中使用嵌套列