当前位置:网站首页>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;
}
从以上例子中可以看出,属性值的所代表的偏移位置,了解各属性值所代表的偏移位置后可以很灵活得使元素按照某一基准点进行旋转。
边栏推荐
- 请教一个问题,flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取全量数据
- Implementation of AVL tree
- Prime partner of Huawei machine test questions
- [noi simulation] regional division (conclusion, structure)
- MySQL的主从复制原理
- Please tell me how to monitor multiple schemas and tables by listening to PgSQL
- Data of all class a scenic spots in China in 2022 (13604)
- This article introduces you to the characteristics, purposes and basic function examples of static routing
- 根据IP获取地市
- Config分布式配置中心
猜你喜欢
Matlab tips (29) polynomial fitting plotfit
异步组件和Suspense(真实开发中)
How can clothing stores make profits?
剑指offer-高质量的代码
.net core 访问不常见的静态文件类型(MIME 类型)
Leetcode T1165: 日志分析
RuntimeError: CUDA error: CUBLAS_ STATUS_ ALLOC_ Failed when calling `cublascreate (handle) `problem solving
freeswitch拨打分机号源代码跟踪
Answer to the first stage of the assignment of "information security management and evaluation" of the higher vocational group of the 2018 Jiangsu Vocational College skills competition
This article introduces you to the characteristics, purposes and basic function examples of static routing
随机推荐
多学科融合
Sqlserver multithreaded query problem
算法---比特位计数(Kotlin)
【mysqld】Can't create/write to file
oracle如何备份索引
freeswitch拨打分机号源代码跟踪
数据资产管理与数据安全国内外最新趋势
MySQL SQL的完整处理流程
7天零基础能考证HCIA吗?华为认证系统学习路线分享
mysql查看bin log 并恢复数据
MySQL binlog related commands
Jetpack Compose 远不止是一个UI框架这么简单~
Complete process of MySQL SQL
MYSQL----导入导出&视图&索引&执行计划
Matlab tips (29) polynomial fitting plotfit
JWT的基础介绍
AVL树的实现
After the promotion, sales volume and flow are both. Is it really easy to relax?
SolidWorks的GB库(钢型材库,包括铝型材、铝管等结构)安装及使用教程(生成铝型材为例)
CompletableFuture使用详解