【CSS3】化神篇

目录

  • 平面转换
    • 平移
    • 旋转
    • 改变旋转原点
    • 多重转换
    • 缩放
    • 倾斜
  • 渐变
    • 线性渐变
    • 径向渐变
  • 空间转换
    • 平移
    • 视距
    • 旋转
    • 立体呈现
    • 缩放
  • 动画
    • 使现步骤
    • animation 复合属性
    • animation 属性拆分
    • 逐帧动画
    • 多组动画

平面转换

作用:为元素添加动态效果,一般与过渡配合使用

概念:改变盒子在平面内的形态(位移、旋转、缩放、倾斜)

平面转换又叫 2D 转换

属性名:transform

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{margin: 100px 0;width: 100px;height: 100px;background-color: #e08b8b;transition: all 1s;}div:hover{transform: translate(700px) rotate(360deg) scale(2) skew(360deg);}</style>
</head>
<body><div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 153147

平移

属性名:transform: translate(X轴移动距离, Y轴移动距离);

属性值:

  • 像素单位数值
  • 百分比(参照盒子自身尺寸计算结果)
  • 正负均可

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.father{width: 500px;height: 300px;margin: 100px auto;border: 1px solid black;}.son{width: 200px;height: 100px;background-color: antiquewhite;transition: all 0.5s;}.father:hover .son{transform: translate(150%,200%);}</style>
</head>
<body><div class="father"><div class="son"></div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 154956

注意事项:

  • translate() 只写一个值,表示沿着 X 轴移动
  • 单独设置 X 或 Y 轴移动距离:translateX() 或 translateY()

旋转

属性名:transform: rotate(旋转角度);

属性值:

  • 角度单位是 deg
  • 取值正负均可
  • 取正顺时针旋转,取负逆时针旋转

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>img{width: 200px;transition: all 1s;}img:hover{transform: rotate(360deg);}</style>
</head>
<body><img src="./img/3.jpg" alt="">
</body>
</html>

结果如下:

屏幕录制 2025-03-13 162633

改变旋转原点

默认情况下,旋转远点是盒子中心点

属性名:transform-origin: 水平原点位置 垂直原点位置;

属性值:

  • 方位名称(left、top、right、bottom、center)
  • 像素单位数值
  • 百分比

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>img{width: 200px;transition: all 1s;transform-origin: right bottom;}img:hover{transform: rotate(360deg);}</style>
</head>
<body><img src="./img/3.jpg" alt="">
</body>
</html>

结果如下:

屏幕录制 2025-03-13 163957

多重转换

先平移再旋转

属性名:transform: translate() rotate();

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 1200px;height: 200px;border: 1px solid black;}img{width: 200px;transition: all 4s;}div:hover img{transform: translateX(500%) rotate(360deg);}</style>
</head>
<body><div><img src="./img/4.jpg" alt=""></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 165216

注意事项:

  • 不能先旋转再平移,因为旋转会改变坐标轴向
  • 复合属性不能分开写,否则后面的属性会覆盖前面的属性

缩放

属性名:

  • transform: scale(缩放倍数);
  • transform: scale(X轴缩放倍数, Y轴缩放倍数);

属性值:

  • 通常只为 scale() 设置一个值,表示 X 轴和 Y 轴等比例缩放
  • 取值大于 1 表示放大,取值小于 1 表示缩小

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 200px;height: 143px;margin: 100px auto;}img{width: 200px;transition: all 4s;}div:hover img{transform: scale(2);}</style>
</head>
<body><div><img src="./img/4.png" alt=""></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 171831

倾斜

属性名:transform: skew();

属性值:

  • 角度度数 deg
  • 取正向左倾斜,取负向右倾斜

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 200px;height: 143px;margin: 100px auto;}img{width: 200px;transition: all 2s;}div:hover img{transform: skew(30deg)}</style>
</head>
<body><div><img src="./img/4.png" alt=""></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 174606

渐变

渐变是多个颜色逐渐变化的效果,一般用于设置盒子背景

线性渐变

属性名:

background-image: linear-gradient(渐变方向,颜色1 终点位置,颜色2 终点位置,......
);

属性值:

  • 渐变方向:(可选)
    • to 方位名词
    • 角度度数
  • 终点位置:(可选)
    • 百分比

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 200px;height: 200px;background-color: #a0adf7;background-image: linear-gradient(45deg, red,#f8a4a4,#a0adf7);}</style>
</head>
<body><div></div>
</body>
</html>

结果如下:
在这里插入图片描述

径向渐变

作用:给按钮添加高光效果

属性名:

background-image: radial-gradient(半径 at 圆心位置,颜色1 终点位置,颜色2 终点位置,......
);

属性值:

  • 半径可以是两条,则为椭圆
  • 圆心位置取值:像素单位数值/百分比/方位名词

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 100px;height: 100px;background-color: pink;border-radius: 50%;background-image: radial-gradient(50px at center center,red,pink);}button{width: 100px;height: 40px;background-color: purple;border: 0;border-radius: 5px;color: white;background-image: radial-gradient(30px at center center,rgba(255,255,255,0.2),transparent);}</style>
</head>
<body><div></div><button>按钮</button>
</body>
</html>

结果如下:
在这里插入图片描述

空间转换

空间:是从坐标轴角度定义的 X、Y 和 Z 三条坐标轴构成了一个立体空间,Z 轴与视线方向相同

空间转换也叫 3D 转换

属性:transform

平移

属性名:

  • transform: translate3d(x,y,z);
  • transform: translateX();
  • transform: translateY();
  • transform: translateZ();

属性值:

  • 像素单位数值
  • 百分比(参照盒子自身尺寸计算结果)

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box{width: 200px;height: 200px;margin: 100px auto;background-color: pink;transition: all 0.5s;}.box:hover{transform: translate3d(100px,200px,300px);}</style>
</head>
<body><div class="box"></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 194159

注意事项:默认无法观察 Z 轴平移效果

视距

作用:制定了观察者与 z=0 平面的距离,为元素添加透视效果

透视效果:近大远小、近实远虚

属性名:perspective: 视距;

属性值:

  • 添加给父级,取值范围 800-1200

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.father{perspective: 1000px;}.son{width: 200px;height: 200px;margin: 100px auto;background-color: pink;transition: all 0.5;}.son:hover{transform: translateZ(-300px);}</style>
</head>
<body><div class="father"><div class="son"></div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 195356

旋转

属性名:

transform: rotateZ() 沿着 Z 轴旋转

transform: rotateX() 沿着 X 轴旋转

transform: rotateY() 沿着 Y 轴旋转

transform: rotate3d(x,y,z,角度度数); x,y,z 取值为 0-1 之间的数字

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 300px;margin: 100px auto;perspective: 1000px;}img{width: 200px;transition: all 2s;}.d1 img:hover{transform: rotateZ(360deg);}.d2 img:hover{transform: rotateX(60deg);}.d3 img:hover{transform: rotateY(60deg);}</style>
</head>
<body><div class="d1"><img src="./img/3.jpg" alt=""></div><div class="d2"><img src="./img/1.png" alt=""></div><div class="d3"><img src="./img/2.png" alt=""></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 201450

左手法则

根据旋转方向确定取值正负

左手握住旋转轴,拇指指向正值方向,其他四个手指弯曲方向为旋转正值方向
在这里插入图片描述

立体呈现

作用:设置元素的子元素是位于 3D 空间中还是平面中

属性名:transform-style

属性值:

  • flat:子级处于平面中
  • preserve-3d:子级处于 3D 空间中

呈现立体图形步骤:

  1. 父元素添加 transform-style: preserve-3d;
  2. 子级定位
  3. 调整子盒子的位置(位移或旋转)
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.cube{position: relative;width: 200px;height: 200px;margin: 100px auto;/* background-color: pink; */transition: all 1s;transform-style: preserve-3d;}.cube div{position: absolute;left: 0;top: 0;width: 200px;height: 200px;}.front{background-color: orange;transform: translateZ(100px);}.back{background-color: green;transform: translateZ(-100px);}.cube:hover{transform: rotateY(90deg);}</style>
</head>
<body><div class="cube"><div class="front">前面</div><div class="back">后面</div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 213518

缩放

属性名:

  • transform: scale3d(x,y,z);
  • transform: scaleX();
  • transform: scaleY();
  • transform: scaleZ();

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.cube{position: relative;width: 200px;height: 200px;margin: 100px auto;/* background-color: pink; */transition: all 4s;transform-style: preserve-3d;transform: scale3d(1.5,2,3);}.cube div{position: absolute;left: 0;top: 0;width: 200px;height: 200px;}.front{background-color: orange;transform: translateZ(100px);}.back{background-color: green;transform: translateZ(-100px);}.cube:hover{transform: rotate3d(1,1,1,90deg);}</style>
</head>
<body><div class="cube"><div class="front">前面</div><div class="back">后面</div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 220517

动画

过渡:实现两个状态间的变化过程

动画:实现多个动态间的变化过程,动画过程可控(重复播放、最终画面、是否暂停)

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.d1{width: 1000px;height: 200px;border: 1px solid black;}.d2{width: 200px;height: 200px;background-color: pink;animation: change 1s infinite alternate;}@keyframes change {0% {transform: translate(0);}100% {transform: translate(800px);}}</style>
</head>
<body><div class="d1"><div class="d2"></div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 221903

使现步骤

定义动画

  • 两个状态
@keyframes 动画名称 {from {}to {}
}
  • 多个状态
@keyframes 动画名称 {0% {}10% {}......100% {}
}

使用动画

animation: 动画名称 动画花费时长;

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 200px;height: 200px;background-color: pink;animation: change 10s;}@keyframes change {0% {width: 200px;height: 200px;}25% {width: 400px;height: 200px;}75% {width: 400px;height: 400px;}100% {border-radius: 50%;}}</style>
</head>
<body><div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-13 235715

animation 复合属性

animation: 动画名称 动画时长 速度曲线 延迟时间 重复次数 动画方向 执行完毕时状态;

  • 速度曲线:
    • linear:匀速运动
    • steps():括号里填数字,表示分几步完成动画
  • 重复次数:
    • infinite:无限循环重复播放
  • 动画方向:
    • alternate:反向执行
  • 执行完毕时状态:
    • backwards:开始状态
    • forwards:结束状态

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box{width: 200px;height: 100px;background-color: pink;animation:  change 1s linear 1s 3 alternate forwards;}@keyframes change {from {width: 200px;}to {width: 800px;}}</style>
</head>
<body><div class="box"></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-14 002430

注意事项:

  • 动画名称和动画时长必须赋值
  • 取值不分先后顺序
  • 如果有两个时间值,第一个时间值表示动画时长,第二个时间值表示延迟时间

animation 属性拆分

属性作用取值
animation-name动画名称
animation-duration动画时长
animation-delay延迟时间
animation-fill-mode动画执行完毕时状态forwards:最后一帧状态
backwards:第一帧状态
animation-timing-function速度曲线steps (数字):逐帧动画
animation-iteration-count重复次数infinite 为无限循环
animation-direction动画执行方向alternate 为反向
animation-play-state暂停动画paused 为暂停,通常配合:hover 使用

逐帧动画

核心原理:

  • steps() 逐帧动画
  • CSS 精灵图

精灵动画制作步骤:

  1. 准备显示区域:盒子尺寸与一张精灵小图尺寸相同
  2. 定义动画:移动背景图(移动距离 = 精灵图宽度)
  3. 使用动画:strps(N),N 与精灵小图个数相同

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 140px;height: 140px;border: 1px solid black;background-image: url(./img/01.png);animation: run 1s steps(12) infinite;}</style>
</head>
<body><div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-14 144049

多组动画

语法格式:

animation: 动画1,动画2,......
;

代码示例:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>div{width: 140px;height: 140px;/* border: 1px solid black; */background-image: url(./img/01.png);animation: run 1s steps(12) infinite,move 5s linear forwards;}@keyframes run {from {background-position: 0 0;}            to {background-position: -1680px 0;}}@keyframes move {0% {transform: translate(0);}100% {transform: translate(800px);}}</style>
</head>
<body><div></div>
</body>
</html>

结果如下:

屏幕录制 2025-03-14 144234

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/72634.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java 线程创建全解析:五种方式详细对比与实战示例

目录 Java 线程创建全解析&#xff1a;五种方式详细对比与实战示例一、引言二、创建线程的五种方式1. 继承 Thread 类2. 实现 Runnable 接口3. 匿名内部类实现 Thread4. 匿名内部类实现 Runnable5. 使用 Lambda 表达式&#xff08;Java 8及以上&#xff09; 三、线程创建方式对…

Dify平台离线镜像部署

Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务&#xff08;Backend as Service&#xff09;和 LLMOps 的理念&#xff0c;使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员&#xff0c;也能参与到 AI 应用的定义和数据运营过程中。 前提…

Unitest和pytest区别

1️⃣ 设计理念 ➡️ unittest &#xff1a; 是 Python 标准库的一部分&#xff0c;设计灵感来自 Java 的 JUnit&#xff0c;强调面向对象的测试模式。 测试用例需要继承 unittest.TestCase 类&#xff0c;测试方法以 test_ 开头。 更适合传统、结构化的测试开发方式。 ⭕ pyte…

GIT标签(Tag)操作

在Git中&#xff0c;标签&#xff08;Tag&#xff09;用于标记特定的提交点&#xff0c;通常用于发布版本。 切换到需要打标签的分支&#xff1a; git checkout <branch-name>创建标签 git tag v1.0.0 git tag -a v1.0.0 -m "Release version 1.0.0"查看所…

玩转github

me github 可以给仓库添加开发人员吗 4o 是的&#xff0c;GitHub允许仓库管理员为仓库添加开发人员&#xff0c;并设置这些开发人员的角色和权限。这里是一个简单的步骤指导&#xff0c;教你如何给一个 GitHub 仓库添加开发人员&#xff1a; 前提条件 你必须有这个仓库的权限&…

EDAS:投稿经验-word版本-问题解决

1. 字体不对&#xff0c;字体未嵌入问题 问题&#xff1a;word转PDF后&#xff0c;总是显示有字体格式不对&#xff08;忘记截图了&#xff09;。 办法&#xff1a;1. EDAS投稿PDF格式问题-CSDN博客-PDF上修改 IEEE论文检测的字体未嵌入问题Times New Ro…

如何在Django中有效地使用Celery进行定时任务?

当我们谈到Web开发时&#xff0c;Django无疑是一个非常流行的框架。而Celery则是与Django配合使用的强大任务队列工具。今天&#xff0c;我们来聊聊如何在Django中使用Celery来实现定时任务。定时任务在很多场景下都非常有用&#xff0c;比如定期发送邮件、清理数据库、执行数据…

声学建模中用于构音障碍语音识别的特征选择意义

声学建模中用于构音障碍语音识别的特征选择意义 原文:Significance of Feature Selection for Acoustic Modeling in Dysarthric Speech Recognition 引言 背景 构音障碍是由运动言语系统的神经损伤引起的,导致发音不清晰。自动语音识别系统对构音障碍语音无效,因其声学差…

【递归与动态规划(DP) C/C++】(1)递归 与 动态规划(DP)

- 第 82 篇 - Date: 2025 - 03 - 17 Author: 郑龙浩/仟濹 【递归与动态规划(DP) C/C】 文章目录 一 递归1基本介绍2 递归技巧**(1) 递归三步法****(2) 思维小技巧** 3 例题(1) 阶乘 (纯递归 or DP)(2) 斐波那契数列 (纯递归 or DP)(3) 汉诺塔 (纯递归 or DP)**① 英文打印过程…

eclipse运行配置,希望带参数该怎么配置

java -Dparam 在eclipse如何配置 在Eclipse中配置-Dparam这样的JVM参数&#xff0c;你可以按照以下步骤进行&#xff1a; 打开Eclipse。 选择菜单栏的"Run" -> "Run Configurations..."。 在弹出的"Run Configurations"窗口左侧&#xff0…

什么是 Fisher 信息矩阵

什么是 Fisher 信息矩阵 Fisher 信息矩阵是统计学和机器学习中一个重要的概念,它用于衡量样本数据所包含的关于模型参数的信息量。 伯努利分布示例 问题描述 假设我们有一个服从伯努利分布的随机变量 X X X,其概率质量函数为 P ( X 

[C++面试] 标准容器面试点

一、入门 1、vector和list的区别 [C面试] vector 面试点总结 vector 是动态数组&#xff0c;它将元素存储在连续的内存空间中。支持随机访问&#xff0c;即可以通过下标快速访问任意位置的元素&#xff0c;时间复杂度为 O(1)&#xff0c;准确点是均摊O(1)。但在中间或开头插…

C++抽象与类的核心概念解析

在C中&#xff0c;抽象&#xff08;Abstraction&#xff09; 是面向对象编程&#xff08;OOP&#xff09;的核心概念之一&#xff0c;它通过隐藏复杂的实现细节&#xff0c;仅暴露必要的接口来实现对现实世界的简化建模。类&#xff08;Class&#xff09; 是实现抽象的核心工具…

C# NX二次开发:拉伸UFUN函数避坑指南

大家好&#xff0c;今天想说一下拉伸相关UFUN函数的使用&#xff0c;尽量让大家别踩坑。 官方给出的拉伸UFUN函数有如下几个&#xff1a; &#xff08;1&#xff09;UF_MODL_create_extruded2 (view source) uf_list_p_tobjectsInputList of objects to be extruded.char *ta…

基于 Python 爬取 TikTok 搜索数据 Tiktok爬虫(2025.3.17)

1. 前言 在数据分析和网络爬虫的应用场景中&#xff0c;我们经常需要获取社交媒体平台的数据&#xff0c;例如 TikTok。本篇文章介绍如何使用 Python 爬取 TikTok 用户搜索数据&#xff0c;并解析其返回的数据。 结果截图 2. 项目环境准备 在正式运行代码之前&#xff0c;我…

AI日报 - 2025年3月18日

AI日报 - 2025年3月18日 &#x1f31f; 今日概览&#xff08;60秒速览&#xff09; ▎&#x1f916; AGI突破 | SOO微调技术减少语言模型欺骗行为10倍 创新对齐技术为更安全AI铺路 ▎&#x1f4bc; 商业动向 | Figure推出全球最高产量人形机器人生产线BotQ 年产1.2万台&#x…

【go】函数类型的作用

Go 语言函数类型的巧妙应用 函数类型在 Go 语言中非常强大&#xff0c;允许将函数作为值进行传递和操作。下面详细介绍函数类型的各种妙用&#xff1a; 1. 回调函数 // 定义一个函数类型 type Callback func(int) int// 接受回调函数的函数 func processData(data []int, ca…

每日一题--进程与协程的区别

进程是什么&#xff1f; 进程&#xff08;Process&#xff09; 是操作系统进行 资源分配和调度的基本单位&#xff0c;代表一个正在执行的程序实例。每个进程拥有独立的虚拟地址空间、代码、数据和系统资源&#xff08;如文件句柄、网络端口等&#xff09;。进程之间通过 IPC&…

关于deepseek R1模型分布式推理效率分析

1、引言 DeepSeek R1 采用了混合专家&#xff08;Mixture of Experts&#xff0c;MoE&#xff09;架构&#xff0c;包含多个专家子网络&#xff0c;并通过一个门控机制动态地激活最相关的专家来处理特定的任务 。DeepSeek R1 总共有 6710 亿个参数&#xff0c;但在每个前向传播…

二叉树算法题实战:从遍历到子树判断

目录 一、引言 二、判断两棵二叉树是否相同 思路 代码实现 注意点 三、二叉树的中序遍历 思路 代码实现 注意点 四、判断一棵树是否为另一棵树的子树 思路 代码实现 注意点 ​编辑 五、补充 一、引言 作者主页&#xff1a;共享家9527-CSDN博客 作者代码仓库&am…