TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The World of CSS Transforms

294 点作者 joshwcomeau将近 4 年前

21 条评论

bobbylarrybobby将近 4 年前
Great article, but one nit: order of transforms matters, yes, but you’re supposed to read them right to left (like matrix multiplication).<p>When you have `transform: translateX(…) rotate(…);`, you’re saying “first rotate it about the origin, then translate it”. When you have `transform: rotate(…) translateX(…);`, you’re saying “first translate it, then rotate it about <i>the</i> origin”! — not the translated object’s origin! That’s why in the the second example the transformed object swings around the origin from a distance when you change the rotation angle.<p>I mean, sure, you can mentally do it left to right and track how the axes change, as the author did, but right to left is a lot simpler, and is what’s actually happening to the vectors behind the scenes.
评论 #28121183 未加载
评论 #28125112 未加载
aenis将近 4 年前
Coming from a person who started writing UIs back in the 1980&#x27;s, where one needed good assembly code to be able to do display text files in text mode, I am seriously impressed how effective browsers are in rendering HTML&#x2F;CSS.<p>For a bunch of scripting languages stacked on top of each other, with byzantine levels of backwards compatibility and alternative ways to define the same things, thats seriously impressive optimisation techniques in the browsers. And they are pretty consistent, too. Absolutely awesome.<p>Of course, I am sure it generates a lot of CO2 for all that effortless eyecandy.
评论 #28119942 未加载
评论 #28120724 未加载
评论 #28120679 未加载
rchaud将近 4 年前
Bookmarked!<p>I know CSS transforms relatively well, but there&#x27;s just no substitute for a well-explained web page with interactive demos!<p>Another similarly laid out web page I find myself going to is a Flexbox tutorial with demos, and toggles that show the difference between flex properties. [0]<p>[0] <a href="https:&#x2F;&#x2F;www.codeinwp.com&#x2F;blog&#x2F;css-flexbox-tutorial&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.codeinwp.com&#x2F;blog&#x2F;css-flexbox-tutorial&#x2F;</a>
orangegreen将近 4 年前
What did people do before CSS transforms?<p>I&#x27;ve been making an app with React Native and react-native-svg and even though react-native-svg supports transformations, I&#x27;ve had to do a lot of transforms with trigonometry (i.e. rotating a shape around a center point, then getting the new bounding box, which requires things such as Math.atan2).<p>It&#x27;s made me really appreciate 1. how much easier front end web development is and 2. how far we&#x27;ve gotten. I cannot tell you how much I appreciate web methods like getBoundingClientRect() or element.closest(), and how easy it is to make animations with CSS and move things around with transforms.
评论 #28119645 未加载
评论 #28118518 未加载
评论 #28118178 未加载
评论 #28118453 未加载
pupppet将近 4 年前
So nice to see an actual personal blog not on Medium, nice design too.
simonw将近 4 年前
This was great - I found the interactive demos really useful and I picked up some good new information from the extra context provided for each transform.<p>I hadn&#x27;t clocked how useful it is that percentage for translate() means the element itself, not it&#x27;s parent container for example.
dmitriid将近 4 年前
&gt; Critically, the item&#x27;s in-flow position doesn&#x27;t change.<p>This is the main problem with animations in CSS: they work as long as you don&#x27;t have to reflow the document, and `transform: translate` is very good for that.<p>But try to slide a new item into a list (or animate as it&#x27;s being removed), and you&#x27;re in for a nasty surprise especially if you don&#x27;t know the height of the element beforehand.
评论 #28119649 未加载
divbzero将近 4 年前
Noteworthy tidbit about percent values:<p><i>There&#x27;s one thing that makes translate ridiculously powerful, though. Something totally unique in the CSS language.</i><p><i>When we use a percentage value in translate, that percentage refers to the element&#x27;s own size, not the available space within the parent container.</i>
评论 #28120206 未加载
评论 #28120261 未加载
dustinlakin将近 4 年前
Excellent content Josh! Something about being able to adjust knobs makes me enjoy diving deep into a subject. I am excited for more of your course&#x2F;posts.
mahoro将近 4 年前
Wow I love this tutorial! It helps to build better connections between enormous tools that CSS provides. As a newbie frontend dev I feel lost in them.<p>Thanks, Josh!
vsareto将近 4 年前
Anyone know if scale(0) shares any properties with the other methods to hide things in CSS? <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;34529598" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;34529598</a><p>I&#x27;m guessing it still takes space, is in flow, and takes clicks?
评论 #28117754 未加载
macando将近 4 年前
This shows how powerful modern CSS is.<p>I too was surprised to discover that the order of transform params matters. Until I swapped them I was getting a completely different and unwanted animation effect.<p>Golden rule of web dev: If you can do it in CSS, do it in CSS.
_greim_将近 4 年前
&gt; This is incredibly handy when we want an element to sit just outside another one<p>Nice! I&#x27;ve been using `position: absolute` + `bottom: 100%` for this. I&#x27;ll be adding this trick to my toolbox.
jamal-kumar将近 4 年前
I love this guy&#x27;s blog. I&#x27;ve been learning so much about modern CSS from it. I highly suggest anyone who wants to get up to speed on this to check out his mailing list.
evanreichard将近 4 年前
Interactive demo doesn&#x27;t appear to work on Firefox?
评论 #28118418 未加载
评论 #28119187 未加载
评论 #28123332 未加载
dheera将近 4 年前
&gt; used the transform property more than 350 times!<p>Of course.<p>-webkit-transform, -o-transform, -ms-transform, -moz-transform, -e-transform, -some-other-bullshit-browser-transform, -khtml-transform, -html-transform ... welcome back to the 90&#x27;s world of brower-specific-internet
oblak将近 4 年前
You can do 3d with CSS but to my knowledge there&#x27;s no way to apply lighting and that, to me, is the real deal breaker. Otherwise people would&#x27;ve done all kinds of unnecessary but cool demos just for the sake of it.
评论 #28123561 未加载
reidjs将近 4 年前
Thanks for all of your classes and tutorials, Josh, they really help me understand how to use CSS to get stuff done.
tintt将近 4 年前
It’s cool, but 2D transformations are easy to wrap your head around anyway. Waiting for part two!
jordache将近 4 年前
Do people still regard CSS transform as a solid strategy to invoke GPU powered UI updates?
Donckele将近 4 年前
blank page with “ An unexpected error has occurred.” on latest iphone&#x2F;ios&#x2F;safari?
评论 #28119157 未加载