H5C3
HTML5
一、什么是 HTML5
HTML5
的概念与定义
- 定义:
HTML5
定义了HTML
标准的最新版本,是对HTML
的第五次重大修改,号称下一代的HTML
- 两个概念:
- 是一个新版本的
HTML
语言,定义了新的标签、特性和属性 - 拥有一个强大的技术集,这些技术集是指:
HTML5
、CSS3
、javascript
, 这也是广义上的HTML5
- 是一个新版本的
HTML5
拓展了哪些内容
- 语义化标签
- 本地存储
- 兼容特性
2D
、3D
- 动画、过渡
CSS3
特性- 性能与集成
二、HTML5
新增标签
-
什么是语义化
-
新增了那些语义化标签
header
--- 头部标签nav
--- 导航标签article
--- 内容标签section
--- 块级标签aside
--- 侧边栏标签footer
--- 尾部标签
- 使用语义化标签的注意
- 语义化标签主要针对**搜索引擎**
- 新标签可以使用一次或者**多次**
- 在 `IE9` 浏览器中,需要把语义化标签都转换为**块级元素**
- 语义化标签,在移动端支持比较友好,
- 另外,`HTML5` 新增的了很多的语义化标签,随着课程深入,还会学习到其他的
三、多媒体音频标签
- 多媒体标签有两个,分别是
- 音频 --
audio
- 视频 --
video
audio
标签说明
- 可以在不使用标签的情况下,也能够原生的支持音频格式文件的播放,
- 但是:播放格式是有限的
-
audio 支持的音频格式
-
audio 目前支持三种格式
-
-
audio 的参数
语法格式
<audio src="./media/snow.mp3" controls autoplay></audio>
5、audio 代码演示
<body>
<!-- 注意:在 chrome 浏览器中已经禁用了 autoplay 属性 -->
<!-- <audio src="./media/snow.mp3" controls autoplay></audio> -->
<!--
因为不同浏览器支持不同的格式,所以我们采取的方案是这个音频准备多个文件
-->
<audio controls>
<source src="./media/snow.mp3" type="audio/mpeg" />
</audio>
</body>
四、多媒体视频标签
-
video 视频标签
- 目前支持三种格式
-
语法格式
<video src="./media/video.mp4" controls="controls"></video>
-
video 参数
-
video 代码演示
<body> <!-- <video src="./media/video.mp4" controls="controls"></video> --> <!-- 谷歌浏览器禁用了自动播放功能,如果想自动播放,需要添加 muted 属性 --> <video controls="controls" autoplay muted loop poster="./media/pig.jpg"> <source src="./media/video.mp4" type="video/mp4"> <source src="./media/video.ogg" type="video/ogg"> </video> </body>
-
多媒体标签总结
- 音频标签与视频标签使用基本一致
- 多媒体标签在不同浏览器下情况不同,存在兼容性问题
- 谷歌浏览器把音频和视频标签的自动播放都禁止了
- 谷歌浏览器中视频添加 muted 标签可以自己播放
- 注意:重点记住使用方法以及自动播放即可,其他属性可以在使用时查找对应的手册
五、新增 input 标签
六、新增表单属性
七、CSS3
属性选择器(上)
-
什么是
CSS3
- 在
CSS2
的基础上拓展、新增的样式
- 在
-
CSS3
发展现状- 移动端支持优于
PC
端 CSS3
目前还草案,在不断改进中CSS3
相对H5
,应用非常广泛
- 移动端支持优于
-
属性选择器列表
类选择器,属性选择器,伪类选择器,权重为10
- 属性选择器代码演示
<!-- disabled 是 禁用 按钮 -->
<button>1</button>
<button>1</button>
<button disabled>1</button>
<button disabled>1</button>
button {
cursor: pointer;
}
button[disabled] {
cursor: default
}
八、CSS3
属性选择器(下)
-
代码演示
<!-- 等于 --> input[type="search"] { color: skyblue; } <!-- 开头 --> span[class^="black"] { color: lightgreen; } <!-- 结尾 --> span[class$="black"] { color: lightsalmon; } <!-- 包含 --> span[class*="black"] { color: lightseagreen; }
九、结构伪类选择器
-
属性列表
-
代码演示
ul li:first-child { background-color: lightseagreen; } ul li:last-child { background-color: lightcoral; } ul li:nth-child(3) { background-color: aqua; }
十、nth-child
参数详解
-
nth-child 详解
-
注意:本质上就是选中第几个子元素
-
n 可以是数字、关键字、公式
-
n 如果是数字,就是选中第几个
-
常见的关键字有
even
偶数、odd
奇数 -
常见的公式如下(如果 n 是公式,则从 0 开始计算)
-
但是第 0 个元素或者超出了元素的个数会被忽略
-
-
代码演示
<style>
/* 偶数 */
ul li:nth-child(even) {
background-color: aquamarine;
}
/* 奇数 */
ul li:nth-child(odd) {
background-color: blueviolet;
}
/*n 是公式,从 0 开始计算 */
ul li:nth-child(n) {
background-color: lightcoral;
}
/* 偶数 */
ul li:nth-child(2n) {
background-color: lightskyblue;
}
/* 奇数 */
ul li:nth-child(2n + 1) {
background-color: lightsalmon;
}
/* 选择第 0 5 10 15, 应该怎么选 */
ul li:nth-child(5n) {
background-color: orangered;
}
/* n + 5 就是从第5个开始往后选择 */
ul li:nth-child(n + 5) {
background-color: peru;
}
/* -n + 5 前五个 */
ul li:nth-child(-n + 5) {
background-color: tan;
}
</style>
注意
<div>
<p>1111</p>
<span>2222</span>
<span>222</span>
<span>222</span>
</div>
<style>
div :nth-child(1) {
background-color: pink;
}
/* 选不到 div的第一个孩子是p*/
/* div span:nth-child(1) {
background-color: paleturquoise;
} */
div span:nth-child(2) {
background-color: paleturquoise;
}
</style>
总结: :nth-child(n) 选择 父元素里面的 第n个孩子 ,不管里面的孩子是否是同一类型
十一、nth-child
和 nt-of-type
的区别
- 代码演示
<style>
div :nth-child(1) {
background-color: lightblue;
}
div :nth-child(2) {
background-color: lightpink;
}
div span:nth-of-type(2) {
background-color: lightseagreen;
}
div span:nth-of-type(3) {
background-color: #fff;
}
</style>
-
区别
nth-child
选择父元素里面的第几个子元素,不管是第几个类型nt-of-type
选择指定类型的元素
十二、伪元素选择器
-
伪类选择器
-
伪类选择器注意事项
before
和after
必须有content
属性before
在内容前面,after 在内容后面before
和after
创建的是一个元素,但是属于行内元素- 创建出来的元素在
Dom
中查找不到,所以称为伪元素 - 伪元素和标签选择器一样,权重为 1
-
代码演示
<style> div { width: 100px; height: 100px; border: 1px solid lightcoral; } div::after, div::before { width: 20px; height: 50px; text-align: center; display: inline-block; } div::after { content: '德'; background-color: lightskyblue; } div::before { content: '道'; background-color: mediumaquamarine; } </style>
十三、伪元素的案例
-
添加字体图标
p { width: 220px; height: 22px; border: 1px solid lightseagreen; margin: 60px; position: relative; } p::after { content: '\ea50'; font-family: 'icomoon'; position: absolute; top: -1px; right: 10px; }
十四、2D
转换之 translate
2D
转换
-
2D
转换是改变标签在二维平面上的位置和形状 -
移动:
translate
-
旋转:
rotate
-
缩放:
scale
translate
语法
- x 就是 x 轴上水平移动
- y 就是 y 轴上水平移动
transform: translate(x, y)
transform: translateX(n)
transfrom: translateY(n)
移动:定位 外内边距 移动(translate)
3. 重点知识点
2D
的移动主要是指 水平、垂直方向上的移动translate
最大的优点就是不影响其他元素的位置translate
中的100%单位,是相对于本身的宽度和高度来进行计算的- 行内标签没有效果
- 代码演示
div {
background-color: lightseagreen;
width: 200px;
height: 100px;
/* 平移 */
/* 水平垂直移动 100px */
/* transform: translate(100px, 100px); */
/* 水平移动 100px */
/* transform: translate(100px, 0) */
/* 垂直移动 100px */
/* transform: translate(0, 100px) */
/* 水平移动 100px */
/* transform: translateX(100px); */
/* 垂直移动 100px */
transform: translateY(100px);
/* 盒子往上走自己高度和宽度的一半 让一个盒子水平垂直居中 */
transfrom: translate(-50%,-50%);
}
十五、2D 转换 rotate
一、rotate
-
rotate 旋转
2D
旋转指的是让元素在二维平面内顺时针或者逆时针旋转
-
rotate
语法
/* 单位是:deg */
transform: rotate(度数)
- 重点知识点
rotate
里面跟度数,单位是deg
- 角度为正时,顺时针,角度为负时,逆时针
- 默认旋转的中心点是元素的中心点
- 代码演示
img{
/*过渡写在本身上,谁做动画给谁加*/
transition: all 0.3s;
}
img:hover {
transform: rotate(360deg) ;
}
- 三角
<style>
div {
position: relative;
width: 249px;
height: 35px;
border: 1px solid #000;
}
div::after {
content: "";
position: absolute;
top: 8px;
right: 15px;
width: 10px;
height: 10px;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
transform: rotate(45deg);
translate: all 0.3s;
}
div:hover::after {
transform: rotate(225deg);
}
</style>
<div></div>
二、设置元素旋转中心点(transform-origin)
transform-origin
基础语法
transform-origin: x y;
- 重要知识点
- 注意后面的参数 x 和 y 用空格隔开
- x y 默认旋转的中心点是元素的中心 (50% 50%),等价于
center
center
- 还可以给 x y 设置像素或者方位名词(
top
、bottom
、left
、right
、center
)
三、旋转中心案例
- 代码演示
<style>
div {
overflow: hidden;
width: 200px;
height: 200px;
border: 1px solid red;
margin: 100px auto;
}
div::before {
content: "134";
width: 100%;
height: 100%;
display: block;
background-color: pink;
transform: rotate(180deg);
transform-origin: left bottom;
transition: all 0.4s;
}
div:hover::before {
transform: rotate(0deg);
}
</style>
<div></div>
四、2D
转换之 scale
-
scale
的作用- 用来控制元素的放大与缩小
-
语法
transform: scale(x, y)
-
知识要点
- 注意,x 与 y 之间使用逗号进行分隔
transform: scale(1, 1)
: 宽高都放大一倍,相当于没有放大transform: scale(2, 2)
: 宽和高都放大了二倍transform: scale(2)
: 如果只写了一个参数,第二个参数就和第一个参数一致transform:scale(0.5, 0.5)
: 缩小scale
最大的优势:可以设置转换中心点缩放,默认以中心点缩放,而且不影响其他盒子
-
代码演示
div:hover { /* 注意,数字是倍数的含义,所以不需要加单位 */ /* transform: scale(2, 2) */ /* 实现等比缩放,同时修改宽与高 */ /* transform: scale(2) */ /* 小于 1 就等于缩放*/ transform: scale(0.5, 0.5) }
五、图片放大案例
- 代码演示
<style>
div {
overflow: hidden;
float: left;
margin: 10px;
}
img {
translate: all 0.4;
}
div img:hover {
transform: scale(1.1);
}
</style>
<div>
<a href="#"><img src="tupian/3.jpg" alt=""></a>
</div>
六、分页按钮案例
- 代码演示
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
<style>
li {
float: left;
width: 30px;
height: 30px;
margin: 10px;
border: 1px solid pink;
text-align: center;
line-height: 30px;
border-radius: 50%;
list-style: none;
translate: all 0.4s;
}
****
li:hover {
transform: scale(1.3);
}
</style>
七、 2D
转换综合写法以及顺序问题
- 知识要点
- 同时使用多个转换,其格式为
transform: translate() rotate() scale()
- 顺序会影响到转换的效果(先旋转会改变坐标轴方向)
- 但我们同时有位置或者其他属性的时候,要将位移放到最前面
- 代码演示
div:hover {
transform: translate(200px, 0) rotate(360deg) scale(1.2)
}
八、 动画(animation)
-
什么是动画
- 动画是
CSS3
中最具颠覆性的特征之一,可通过设置多个节点来精确的控制一个或者一组动画,从而实现复杂的动画效果
- 动画是
-
动画的基本使用
- 先定义动画
- 在调用定义好的动画
-
语法格式(定义动画)
@keyframes 动画名称 { 0% { width: 100px; } 100% { width: 200px } }
-
语法格式(使用动画)
div {
/* 调用动画 */
animation-name: 动画名称;
/* 持续时间 */
animation-duration: 持续时间;
}
九、动画序列
-
动画序列
- 0% 是动画的开始,100 % 是动画的完成,这样的规则就是动画序列
- 在 **@keyframs **中规定某项 CSS 样式,就由创建当前样式逐渐改为新样式的动画效果
- 动画是使元素从一个样式逐渐变化为另一个样式的效果,可以改变任意多的样式任意多的次数
- 用百分比来规定变化发生的时间,或用
from
和to
,等同于 0% 和 100%
-
代码演示
<style> div { width: 100px; height: 100px; background-color: aquamarine; animation-name: move; animation-duration: 0.5s; } @keyframes move{ 0% { transform: translate(0px) } 100% { transform: translate(500px, 0) } } </style>
十、动画常见属性
- 常见的属性
-
代码演示
div { width: 100px; height: 100px; background-color: aquamarine; /* 动画名称 */ animation-name: move; /* 动画花费时长 */ animation-duration: 2s; /* 动画速度曲线 */ animation-timing-function: ease-in-out; /* 动画等待多长时间执行 */ animation-delay: 2s; /* 规定动画播放次数 infinite: 无限循环 */ animation-iteration-count: infinite; /* 是否逆行播放 */ animation-direction: alternate; /* 动画结束之后的状态 */ animation-fill-mode: forwards; } div:hover { /* 规定动画是否暂停或者播放 */ animation-play-state: paused; }
十一、 动画简写方式
- 动画简写方式
/* animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 起始与结束状态 */
animation: name duration timing-function delay iteration-count direction fill-mode
- 知识要点
- 简写属性里面不包含
animation-paly-state
- 暂停动画
animation-paly-state: paused
; 经常和鼠标经过等其他配合使用 - 要想动画走回来,而不是直接调回来:
animation-direction: alternate
- 盒子动画结束后,停在结束位置:
animation-fill-mode: forwards
-
代码演示
animation: move 2s linear 1s infinite alternate forwards;
十二、速度曲线细节
- 速度曲线细节
animation-timing-function
: 规定动画的速度曲线,默认是ease
-
代码演示---打字机效果
div { overflow: hidden; width: 0px; height: 50px; line-height: 50px; /*让文字强制一行显示*/ white-space: nowrap; overflow: hidden; background-color: aquamarine; /*steps 就是分几步来完成动画 有了steps就不用写ease 或 linear */ animation: move 4s steps(24) forwards; } @keyframes move { 0% { width: 0px; } 100% { width: 480px; } }
十三、奔跑的熊大
- 代码演示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color: #ccc;
}
div {
position: absolute;
width: 200px;
height: 100px;
background: url(media/bear.png) no-repeat;
/* 我们元素可以添加多个动画, 用逗号分隔 */
animation: bear .4s steps(8) infinite, move 3s forwards;
}
@keyframes bear {
0% {
background-position: 0 0;
}
100% {
background-position: -1600px 0;
}
}
@keyframes move {
0% {
left: 0;
}
100% {
left: 50%;
/* margin-left: -100px; */
transform: translateX(-50%);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
十四、热点图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color: #333333;
}
.map {
position: relative;
width: 747px;
height: 616px;
background: url(tupian/map.png) no-repeat;
margin: 0 auto;
}
.city {
position: absolute;
top: 227px;
right: 193px;
color: #ffffff;
}
.dotted {
width: 8px;
height: 8px;
background-color: #09f;
border-radius: 50%;
}
.city div[class^="pulse"] {
/* 保证小波纹在父盒子里面水平垂直居中 放大之后会向四周发散 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 8px;
height: 8px;
box-shadow: 0 0 12px #009dfd;
border-radius: 50%;
animation: pulse 1.2s linear infinite;
}
.city div.pulse2 {
animation-delay: 0.4s;
}
.city div.pulse3 {
animation-delay: 0.8s;
}
@keyframes pulse {
0% {}
70% {
/* transform: scale(3) 会让阴影变大 */
width: 40px;
height: 40px;
opacity: 1;
}
100% {
width: 70px;
height: 70px;
opacity: 0;
}
}
</style>
</head>
<body>
<div class="map">
<div class="city">
<div class="dotted"></div>
<div class="pulse1"></div>
<div class="pulse2"></div>
<div class="pulse3"></div>
</div>
</div>
</body>
</html>
一、 认识 3D
转换
3D
的特点- 近大远小
- 物体和面遮挡不可见
- 三维坐标系
-
x 轴:水平向右 -- 注意:x 轴右边是正值,左边是负值
-
y 轴:垂直向下 -- 注意:y 轴下面是正值,上面是负值
-
z 轴:垂直屏幕 -- 注意:往外边的是正值,往里面的是负值
-
二、3D
转换
-
3D
转换知识要点3D
位移:translate3d(x, y, z)
3D
旋转:rotate3d(x, y, z)
- 透视:
perspctive
3D
呈现transfrom-style
-
3D
移动translate3d
3D
移动就是在2D
移动的基础上多加了一个可以移动的方向,就是 z 轴方向transform: translateX(100px)
:仅仅是在 x 轴上移动transform: translateY(100px)
:仅仅是在 y 轴上移动transform: translateZ(100px)
:仅仅是在 z 轴上移动transform: translate3d(x, y, z)
:其中x、y、z 分别指要移动的轴的方向的距离- 注意:x, y, z 对应的值不能省略,不需要填写用 0 进行填充
- 语法
transform: translate3d(x, y, z)
- 代码演示
transform: translate3d(100px, 100px, 100px)
/* 注意:x, y, z 对应的值不能省略,不需要填写用 0 进行填充 */
transform: translate3d(100px, 100px, 0)
三、透视 perspective
-
知识点讲解
- 如果想要网页产生
3D
效果需要透视(理解成3D
物体投影的2D
平面上) - 实际上模仿人类的视觉位置,可视为安排一直眼睛去看
- 透视也称为视距,所谓的视距就是人的眼睛到屏幕的距离
- 距离视觉点越近的在电脑平面成像越大,越远成像越小
- 透视的单位是像素
- 如果想要网页产生
-
知识要点
- 透视需要写在被视察元素的父盒子上面
- 注意下方图片
-
d:就是视距,视距就是指人的眼睛到屏幕的距离 (透视
perspective
) -
z:就是 z 轴,z 轴越大(正值),我们看到的物体就越大 (
translateZ
)
-
-
代码演示
body { /*透视写到被观察元素的父盒子上面 透视越大 盒子越小 */ perspective: 1000px; }
四、 translateZ
translateZ
与perspecitve
的区别
perspecitve
给父级进行设置,translateZ
给 子元素进行设置不同的大小
五、3D
旋转rotateX
3D 旋转指可以让元素在三维平面内沿着 x 轴、y 轴、z 轴 或者自定义轴进行旋转
-
语法
transform: rotateX(45deg)
-- 沿着 x 轴正方向旋转 45 度transform: rotateY(45deg)
-- 沿着 y 轴正方向旋转 45 度transform: rotateZ(45deg)
-- 沿着 z 轴正方向旋转 45 度transform: rotate3d(x, y, z, 45deg)
-- 沿着自定义轴旋转 45 deg 为角度
-
代码案例
div {
perspective: 300px;
}
img {
display: block;
margin: 100px auto;
transition: all 1s;
}
img:hover {
transform: rotateX(-45deg)
}
-
左手准则
-
左手的手拇指指向 x 轴的正方向
-
其余手指的弯曲方向就是该元素沿着 x 轴旋转的方向
-
六、3D
旋转 rotateY
- 代码演示
div {
perspective: 500px;
}
img {
display: block;
margin: 100px auto;
transition: all 1s;
}
img:hover {
transform: rotateY(180deg)
}
-
左手准则
-
左手的拇指指向 y 轴的正方向
-
其余的手指弯曲方向就是该元素沿着 y 轴旋转的方向(正值)
-
七、 3D
旋转 rotateZ
- 代码演示
div {
perspective: 500px;
}
img {
display: block;
margin: 100px auto;
transition: all 1s;
}
img:hover {
transform: rotateZ(180deg)
}
rotate3d
transform: rotate3d(x, y, z, deg)
-- 沿着自定义轴旋转 deg 为角度- x, y, z 表示旋转轴的矢量,是标识你是否希望沿着该轴进行旋转,最后一个标识旋转的角度
transform: rotate3d(1, 1, 0, 180deg)
-- 沿着对角线旋转 45degtransform: rotate3d(1, 0, 0, 180deg)
-- 沿着 x 轴旋转 45deg
-
代码演示
div { perspective: 500px; } img { display: block; margin: 100px auto; transition: all 1s; } img:hover { transform: rotate3d(1, 1, 0, 180deg) }
八、
3D
呈现transform-style
(重要)-
transform-style
- 控制子元素是否开启三维立体环境
transform-style: flat
代表子元素不开启3D
立体空间,默认的transform-style: preserve-3d
子元素开启立体空间- 代码写给父级,但是影响的是子盒子
-
代码演示
-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
perspective: 500px;
}
.box {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
translate: all 3s;
/* 让子元素保持3D立体空间环境 */
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(60deg);
}
.box div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: pink;
}
.box div:last-child {
background-color: red;
transform: rotateX(60deg);
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
</div>
</body>
</html>
案例-两面翻转的盒子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
perspective: 400px;
}
.box {
position: relative;
width: 300px;
height: 300px;
margin: 100px auto;
transition: all .4s;
/* 让背面的紫色盒子保留立体空间 给父级添加的 */
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
font-size: 30px;
color: #fff;
text-align: center;
line-height: 300px;
}
.front {
background-color: pink;
z-index: 1;
}
.back {
background-color: purple;
/* 像手机一样 背靠背 旋转 */
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="box">
<div class="front"></div>
<div class="back"></div>
</div>
</body>
</html>
3D导航栏
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
margin: 100px;
}
ul li {
float: left;
width: 200px;
height: 50px;
list-style: none;
perspective: 500px;
}
.box {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
translate: all 3s;
}
.box:hover {
transform: rotateX(90deg);
}
.front,
.bottom {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.front {
z-index: 1;
background-color: red;
transform: translateZ(25px);
}
.bottom {
/* transfrom写多个属性 translate 一定写在前面 */
transform: translateY(25px) rotateX(-90deg);
background-color: pink;
}
</style>
</head>
<body>
<ul>
<li>
<div class="box">
<div class="front">前面</div>
<div class="bottom">下面</div>
</div>
</li>
<li>
<div class="box">
<div class="front">前面</div>
<div class="bottom">下面</div>
</div>
</li>
<li>
<div class="box">
<div class="front">前面</div>
<div class="bottom">下面</div>
</div>
</li>
</ul>
</body>
</html>
旋转木马
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
perspective: 800px;
}
section {
position: relative;
width: 300px;
height: 200px;
margin: 150px auto;
transform-style: preserve-3d;
animation: rotate 10s linear infinite;
}
section:hover {
animation-play-state: paused;
}
div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(tupian/dog.jpg) no-repeat;
}
section div:nth-child(1) {
transform: rotateY(0) translateZ(300px);
}
section div:nth-child(2) {
/* 先旋转好了再 移动距离 */
transform: rotateY(60deg) translateZ(300px);
}
section div:nth-child(3) {
/* 先旋转好了再 移动距离 */
transform: rotateY(120deg) translateZ(300px);
}
section div:nth-child(4) {
/* 先旋转好了再 移动距离 */
transform: rotateY(180deg) translateZ(300px);
}
section div:nth-child(5) {
/* 先旋转好了再 移动距离 */
transform: rotateY(240deg) translateZ(300px);
}
section div:nth-child(6) {
/* 先旋转好了再 移动距离 */
transform: rotateY(300deg) translateZ(300px);
}
@keyframes rotate {
0% {
transform: rotateY(0);
}
100% {
transform: rotateY(360deg);
}
}
</style>
</head>
<body>
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?