当前位置:网站首页>transform-origin属性详解
transform-origin属性详解
2022-07-07 03:22:00 【鹿蹊zz】
transform-origin用于设置动画的基点(中心点) , 适用于所有块级元素及某些内联元素。
必须配合transform使用 默认情况下,元素的动作参考点为元素盒子的中心
可以设置九个位置的值:水平方向: left center right
0 50% 100%
垂直方向: top center bottom
默认值:50% 50% ,相对于center center
两种写法 ,
eg:
transform-origin: left;
transform-origin:0;
语法:
transform-origin: x-axis y-axis z-axis;

属性值详解
<div class="outer">
<div class="inner"></div>
<div class="inner"></div>
</div>1.默认值,以自身原点旋转45deg
.outer {
width: 100px;
height: 100px;
background-color: #6a5acd8c;
margin: 200px;
position: relative;
}
/* (1)默认值旋转,红色为基点 默认值为 transform-origin: 50% 50% 0;*/
.inner {
transform: rotate(45deg);
/* transform-origin: 50% 50% 0; */
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.outer .inner:nth-child(2){
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: 50px;
left: 50px;
}
2.以顶部旋转180deg
.outer {
width: 100px;
height: 100px;
background-color: #6a5acd8c;
margin: 200px;
position: relative;
}
/* (2)以顶部旋转180deg */
.inner {
transform: rotate(180deg);
transform-origin: 50% 0;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: -2.5px;
left: 50px;
} 
3.以右部旋转150deg
/* 以右部旋转150deg 红色为基点 */
.inner {
transform: rotate(150deg);
transform-origin: 100% 50%;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: 47.5px;
left: 97.5px;
}
4.左上角旋转20deg 红色为基点
.inner {
transform: rotate(-20deg);
transform-origin: 0 0;
width: 100%;
height: 100%;
background-color: #6a5acdeb;
}
.inner:nth-child(2) {
width: 5px;
height: 5px;
background-color: red;
transform: none;
position: absolute;
top: -2.5px;
left: -2.5px;
}
从以上例子中可以看出,属性值的所代表的偏移位置,了解各属性值所代表的偏移位置后可以很灵活得使元素按照某一基准点进行旋转。
边栏推荐
- Maze games based on JS
- How can gyms improve their competitiveness?
- . Net core accesses uncommon static file types (MIME types)
- leetcode 509. Fibonacci number
- Precise space-time travel flow regulation system - ultra-high precision positioning system based on UWB
- A slow SQL drags the whole system down
- Please answer the questions about database data transfer
- Special behavior of main function in import statement
- 2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书
- MYSQL----导入导出&视图&索引&执行计划
猜你喜欢

.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context

This article introduces you to the characteristics, purposes and basic function examples of static routing

CompletableFuture使用详解

JWT的基础介绍

Several index utilization of joint index ABC

MYSQL----导入导出&视图&索引&执行计划

关于数据库数据转移的问题,求各位解答下

Network foundation - header, encapsulation and unpacking

How can brand e-commerce grow against the trend? See the future here!

Precise space-time travel flow regulation system - ultra-high precision positioning system based on UWB
随机推荐
Leetcode t1165: log analysis
大促过后,销量与流量兼具,是否真的高枕无忧?
Multithreading and high concurrency (9) -- other synchronization components of AQS (semaphore, reentrantreadwritelock, exchanger)
Learning records on July 4, 2022
请教一个问题,flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取全量数据
组件的嵌套和拆分
SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)
请问 flinksql对接cdc时 如何实现计算某个字段update前后的差异 ?
Jetpack Compose 远不止是一个UI框架这么简单~
leetcode 509. Fibonacci number
Sword finger offer high quality code
Use of completable future
选择商品属性弹框从底部弹出动画效果
Config distributed configuration center
请教一下,监听pgsql ,怎样可以监听多个schema和table
大咖云集|NextArch基金会云开发Meetup来啦
How can gyms improve their competitiveness?
MOS tube parameters μ A method of Cox
DHCP路由器工作原理
MySQL SQL的完整处理流程