热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在CSS中应用多重转换?-HowtoapplymultipletransformsinCSS?

UsingCSS,howcanIapplymorethanonetransform?使用CSS,如何应用多个转换?Example:Inthefollowing,only

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

使用CSS,如何应用多个转换?

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

例:在下面的例子中,只应用翻译,而不是旋转。

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

7 个解决方案

#1


617  

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 attribute.

当您有多个转换指令时,只有最后一个将被应用。就像其他CSS属性一样。

#2


33  

I'm adding this answer not because it's likely to be helpful but just because it's true.

我加这个答案不是因为它可能有用,而是因为它是真的。

In addition to using the existing answers explaining how to make more than one translation by chaining them, you can also construct the 4x4 matrix yourself

除了使用现有的答案来解释如何通过链接实现多个翻译,您还可以自己构建4x4矩阵。

I grabbed the following image from some random site I found while googling which shows rotational matrices:

我从我在谷歌搜索中发现的一些随机的网站上抓取了如下图片:

Rotation around x axis: Rotation around x axis
Rotation around y axis: Rotation around y axis
Rotation around z axis: Rotation around z axis

绕x轴旋转:绕y轴旋转:绕z轴旋转:

I couldn't find a good example of translation, so assuming I remember/understand it right, translation:

我找不到一个翻译的好例子,所以假设我记得/理解它,翻译:

[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[x y z 1]

See more at the Wikipedia article on transformation as well as the Pragamatic CSS3 tutorial which explains it rather well. Another guide I found which explains arbitrary rotation matrices is Egon Rath's notes on matrices

请参阅维基百科关于转换的文章以及实用的CSS3教程,它解释得很好。我发现的另一个解释任意旋转矩阵的指南是Egon Rath关于矩阵的笔记。

Matrix multiplication works between these 4x4 matrices of course, so to perform a rotation followed by a translation, you make the appropriate rotation matrix and multiply it by the translation matrix.

矩阵乘法在这些4 * 4矩阵之间是可以的,所以要做一个旋转,然后是一个平移,你要做一个合适的旋转矩阵并乘以平移矩阵。

This can give you a bit more freedom to get it just right, and will also make it pretty much completely impossible for anyone to understand what it's doing, including you in five minutes.

这可以给你更多的自由来获得它的权利,也会使任何人都不可能理解它在做什么,包括你在五分钟内。

But, you know, it works.

但是,你知道,它是有效的。

Edit: I just realized that I missed mentioning probably the most important and practical use of this, which is to incrementally create complex 3D transformations via Javascript, where things will make a bit more sense.

编辑:我刚刚意识到,我漏掉了可能最重要和最实际的使用方法,即通过Javascript增量地创建复杂的3D转换,这样做会更有意义。

#3


13  

You can also apply multiple transforms using an extra layer of markup e.g.:

您还可以使用额外的标记层来应用多个转换。

Hey!

This can be really useful when animating elements with transforms using Javascript.

这在使用Javascript进行转换的元素时非常有用。

#4


12  

You can apply more than one transform like this:

您可以应用多个这样的转换:

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

#5


0  

A simple way to apply multiple transform is this

这是一个应用多重变换的简单方法。

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

But also don't forget that you need to add prefix to let it work in all browsers as some browers like safari, IE not support tranform property without prefix.

但也不要忘记,您需要添加前缀,以便让它在所有浏览器中工作,就像一些浏览器(如safari)一样(不支持没有前缀的转换属性)。

li:nth-of-type(2){
    transform : translate(-20px, 0px) rotate(15deg);
    -moz-transform : translate(-20px, 0px) rotate(15deg);
    -webkit-transform : translate(-20px, 0px) rotate(15deg);
    -o-transform : translate(-20px, 0px) rotate(15deg);
    -ms-transform : translate(-20px, 0px) rotate(15deg);
}

#6


0  

Just start from there that in CSS, if you repeat 2 values or more, always last one gets applied, unless using !important tag, but at the same time avoid using !important as much as you can, so in your case that's the problem, so the second transform override the first one in this case...

从那里开始,在CSS,如果你重复2或多个值,总是最后一个被应用,除非使用!重要的标签,但同时避免使用!重要的尽可能多的,所以在你的案子的问题,所以第二变换覆盖第一个在这种情况下……

So how you can do what you want then?...

那么,你怎么能做你想做的呢?

Don't worry, transform accepts multiple values at the same time... So this code below will work:

不要担心,转换同时接受多个值…下面的代码将会工作:

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

If you like to play around with transform run the iframe from MDN below:

如果您喜欢使用转换运行iframe从MDN到下面:

Look at the link below for more info:

查看下面的链接了解更多信息:

<>

< >

#7


-3  

For example

例如

-webkit-transform: rotateX(-36.09deg) rotateY(-52.71deg) scaleX(1.3) scaleY(1.3) translateY(31px) ;
transform: rotateX(-36.09deg) rotateY(-52.71deg) scaleX(1.3) scaleY(1.3) translateY(31px) ;
-webkit-transform-origin: 50% 50% 0;
transform-origin: 50% 50% 0;

I am using enjoycss tool

我使用的是乐趣css工具。

http://enjoycss.com/5C#transform

http://enjoycss.com/5C变换

it generates css code for required parameters of transform using GUI to generate the transfrom code ;)

它为所需的转换参数生成css代码,使用GUI生成transfrom代码;

enter image description here


推荐阅读
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 关于如何快速定义自己的数据集,可以参考我的前一篇文章PyTorch中快速加载自定义数据(入门)_晨曦473的博客-CSDN博客刚开始学习P ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了brain的意思、读音、翻译、用法、发音、词组、同反义词等内容,以及脑新东方在线英语词典的相关信息。还包括了brain的词汇搭配、形容词和名词的用法,以及与brain相关的短语和词组。此外,还介绍了与brain相关的医学术语和智囊团等相关内容。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • 开源Keras Faster RCNN模型介绍及代码结构解析
    本文介绍了开源Keras Faster RCNN模型的环境需求和代码结构,包括FasterRCNN源码解析、RPN与classifier定义、data_generators.py文件的功能以及损失计算。同时提供了该模型的开源地址和安装所需的库。 ... [详细]
  • Python中的PyInputPlus模块原文:https ... [详细]
author-avatar
阿悅11
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有