Using CSS, how can I apply more than one transform?

Example: In the following, only the translation is applied, not the rotation.

li:nth-child(2) {
    transform: rotate(15deg);
    transform: translate(-20px,0px);        
}

推荐答案

You have to put them on one line like this:

li:nth-child(2) {
    transform: rotate(15deg) translate(-20px,0px);
}

When you have multiple transform directives, only the last one will be applied. It's like any other CSS rule.


Keep in mind multiple transform one line directives are applied from right to left.

This: transform: scale(1,1.5) rotate(90deg);
and: transform: rotate(90deg) scale(1,1.5);

will not produce the same result:

.orderOne, .orderTwo {
  font-family: sans-serif;
  font-size: 22px;
  color: #000;
  display: inline-block;
}

.orderOne {
  transform: scale(1, 1.5) rotate(90deg);
}

.orderTwo {
  transform: rotate(90deg) scale(1, 1.5);
}
<div class="orderOne">
  A
</div>

<div class="orderTwo">
  A
</div>

Css相关问答推荐

如何在Elm中更改视图时添加过渡?

将照片向下对齐至div并保持响应性

在Powershell中使用正则表达式编辑css文件

Vue3日期 Select 器:作用域样式不起作用

Primeng Angular更改p-dialog背景 colored颜色

当具有外部高度的网格项溢出时,为什么溢出滚动端口填充不应用于网格容器?

在最小和最大视口之间时具有固定值的 CSS 钳位

Img 未拉伸以满足所需的纵横比

我怎样才能准确地获得虚构文本内容宽度的边距?

努力将 CSS 样式应用于 Elm 应用程序

如何给三角形添加渐变?

关键帧不能动画回来

如何使用 TailwindCSS 禁用环形阴影?

CSS Stepper - LI After Overlaying LI Before

使用 CSS 剪辑/裁剪背景图像

CSS中的旋转地球

Bootstrap:在列之间添加边距/填充空间

如何使内容出现在固定的 DIV 元素下方?

通过javascript删除或禁用浏览器的焦点边框

如何实现最大字体大小?