形变-动画-vertical-align
transform
- 对某一个元素进行某些形变,包括旋转,缩放,倾斜或平移等
- transform是形变的意思,transformer就是变形金刚
- 并非所有的盒子都可以进行transform的转换(通常行内级元素不能进行形变)
- transform对于行内级非替换元素是无效的
常见的函数transform function有
- 平移: translate(x, y)
- 缩放: scale(x, y)
- 旋转: rotate(deg)
- 倾斜: skew(deg, deg)
translate
- 平移:translate(x, y)
- 这个css函数用于移动元素在平面上的位置
- translate本身可以表示翻译的意思,在物理上也可以表示平移
- 值的个数
- 一个值
- 设置x轴上的位移
- 二个值
- 设置x轴和y轴上的位移
- 一个值
- 值类型
- 数字
- 100px
- 百分比
- 参照元素本身
- 数字
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
display: inline-block;
border: 5px solid #f00;
}
.container .box {
width: 200px;
height: 200px;
background-color: orange;
transform: translate(100px);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
display: inline-block;
border: 5px solid #f00;
}
.container .box {
width: 200px;
height: 200px;
background-color: orange;
transform: translate(100px, 100px);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
display: inline-block;
border: 5px solid #f00;
}
.container .box {
width: 200px;
height: 200px;
background-color: orange;
/* 百分比相对于自身的 */
transform: translate(100%, 100%);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
水平居中
- 行内级
- text-align: center
- 块级元素
- margin: 0 auto;
- 绝对定位
- 有宽度的情况下,left: 0;/right: 0;/margin: 0 atuo;
- flex
- justify-content: center;
垂直居中
- 绝对定位
- 有高度的情况下,top: 0;/bottom: 0;/marign: auto 0;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
position: relative;
height: 300px;
background-color: orange;
}
.box {
width: 100px;
height: 100px;
background-color: #f00;
position: absolute;
top: 0;
bottom: 0;
margin: auto 0;
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
- flex布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
display: flex;
align-items: center;
height: 300px;
background-color: orange;
}
.box {
background-color: #f00;
}
</style>
</head>
<body>
<div class="container">
<div class="box">box</div>
</div>
</body>
</html>
- top和transforom
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
position: relative;
height: 300px;
background-color: orange;
}
.box {
position: absolute;
top: 50%;
transform: translate(0, -50%);
background-color: #f00;
}
</style>
</head>
<body>
<div class="container">
<div class="box">box</div>
</div>
</body>
</html>
scale
- 缩放: scale(x, y)
- css函数可改变元素的大小
- 值个数
- 一个值
- 设置x轴上的缩放
- 二个值
- 设置x轴和y轴上的缩放
- 一个值
- 值类型
- 数字
- 1 保持不变
- 2 放大一倍
- 0.5 缩小一般
- 百分比
- 百分比不常用
- 数字
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 5px solid #f00;
}
.box {
width: 200px;
height: 200px;
background-color: orange;
transform: scale(0.6, 0.6);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 5px solid #f00;
}
.box {
width: 200px;
height: 200px;
border: 10px solid #0f0;
background-color: orange;
transform: scale(0.6, 0.6);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 20px solid #f00;
}
.box {
width: 200px;
height: 200px;
border: 20px solid #0f0;
background-color: orange;
transform: scale(0.6, 0.6);
}
.box:hover {
transform: scale(1.1, 1.1);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
rotate
- 旋转 rotate(deg)
- 值个数
- 一个值时,表示旋转的角度
- 值类型
- 常用单位deg
- 正数为顺时针
- 负数为逆时针
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 10px solid #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
}
.box:hover {
transform: rotate(90deg);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 10px solid #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
}
.box:hover {
transform: rotate(45deg);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 10px solid #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
}
.box:hover {
transform: rotate(-45deg);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
transform-origin
- transform-origin
- 形变的原点
- 一个值
- 设置x轴的原点
- 第二默认值是center
- 两个值
- 设置x轴和y轴的原点
- 值类型
- left center right bottom关键字
- length
- 百分比
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 10px solid #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
/* 默认值 */
/* transform-origin: center center; */
/* transform-origin: center; */
/* 修改 */
/* transform-origin: left top; */
/* transform-origin: center top; */
transform-origin: 20px 20px;
}
.box:hover {
transform: rotate(45deg) scale(0.5);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
padding-top: 200px;
}
.container {
display: inline-block;
border: 10px solid #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
/* 默认值 */
/* transform-origin: center center; */
/* transform-origin: center; */
/* 修改 */
/* transform-origin: left top; */
/* transform-origin: center top; */
/* transform-origin: 20px 20px; */
/* transform-origin: 10% 10%; */
transform-origin: 10%;
}
.box:hover {
transform: rotate(45deg) scale(0.5);
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
skew
- 倾斜 skew(x, y)
- 函数定义了一个元素在二维平面上的倾斜转换
- 值个数
- 一个值
- x轴上的倾斜
- 二个值
- x轴和y轴上的倾斜
- 一个值
- 值类型
- deg 倾斜的角度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
font-style: italic;
width: 200px;
height: 100px;
background-color: orange;
}
.box:hover {
transform: skew(10deg, 10deg);
}
</style>
</head>
<body>
<div class="box">我是div元素</div>
</body>
</html>
transform多个值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
}
.box:hover {
transform: translateX(50px) scale(1.2) rotate(45deg);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
transition
认识transition动画
什么是transition动画呢
- css transition提供了一种在更改css属性时控制动画的方法
- 可以让css属性变化成为一个持续一段时间的过程,而不是立即生效
- 比如讲一个元素从一个位置移动到另一个位置,默认在修改完css属性后会立即生效
- 但是我们可以通过css transition,让这个过程加上一定的动画效果,包括一定的曲线速率变化
通常将两个状态之间的过渡称为隐式过渡,因为开始与结束之间的状态由浏览器决定
css transition可以决定
- 那些属性发生动画效果
- 何时开始
- 持续多久
- 如果动画
transform
- transition-property
- transition-duration
- transition-timing
- transition-timing-function
- transition-delay
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
position: relative;
left: 0;
width: 200px;
height: 100px;
background-color: orange;
transition: left 2s;
}
.box:hover {
left: 100px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
position: relative;
left: 0;
width: 200px;
height: 100px;
background-color: orange;
/* transition: left 2s; */
transition-property: left;
transition-duration: 1s;
transition-timing-function: ease-in;
}
.box:hover {
left: 100px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
/* transition: left 2s; */
transition-property: transform;
transition-duration: 1s;
transition-timing-function: ease-in;
}
.box:hover {
transform: translate(100px);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
/* transition: left 2s; */
transition-property: transform;
transition-duration: 1s;
transition-timing-function: ease-in;
transition-delay: 2s;
}
.box:hover {
transform: translate(100px);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
transition-property: all;
transition-duration: 1s;
transition-timing-function: ease-in;
transition-delay: 1s;
}
.box:hover {
transform: translate(100px);
width: 500px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
transition: all 1s ease-in 1s;
}
.box:hover {
transform: translate(100px);
width: 500px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container {
background-color: #f00;
}
.box {
width: 200px;
height: 100px;
background-color: orange;
transition: all 1s ease-in 1s;
}
.container:hover .box {
transform: translate(100px);
width: 500px;
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
词汇解读
transform
- transform是形变
- 一个css属性,该css属性用设置形变
- 后面的值是形变的函数,比如scale,rotate,translate
translate
- translate是tranform的其中一个tranform-function
- 用于对元素进行平移
rotate
- rotate是缩放
skew
- skew是倾斜
transition
- transition是过渡
- 它本身也有转变的含义,但是跟多表示的是过渡的意思
宽度变化的方向
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 200px;
background-color: orange;
transition: width 2s;
}
.box:hover {
width: 400px;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
animation
transition的缺点
- 只能定义开始和结束装填,不能定义中间状态,也就是说只有两个状态
- 不能重复执行,除非一再触发动画
- 需要在特定状态下会触发才能执行,比如某个属性被修改了
animation的使用步骤
- 使用@keyframes定义动画序列
- 配置动画执行的名称、持续时间、动画曲线、延迟、执行次数、方向等等
属性
- animation: name duration timing-function delay iteration-count direction fill-mode;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
animation: moveAnim 2s;
}
@keyframes moveAnim {
0% {
transform: translate(0, 0);
}
25% {
transform: translate(0, 200px);
}
50% {
transform: translate(400px, 200px);
}
75% {
transform: translate(400px, 0);
}
100% {
transform: translate(0, 0);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
animation: moveAnim 2s;
}
@keyframes moveAnim {
0% {
transform: translate(0, 0) scale(0.5);
}
33% {
transform: translate(0, 200px) scale(1.2);
}
66% {
transform: translate(400px, 200px) scale(1);
}
100% {
transform: translate(400px, 0) scale(0.5);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
/* animation: moveAnim 2s; */
animation-name: moveAnim;
animation-duration: 3s;
animation-timing-function: ease-in-out;
animation-delay: 2s;
animation-iteration-count: 2;
animation-direction: reverse;
/* animation-fill-mode: forwards; */
animation-fill-mode: backwards;
/* 一般通过JavaScript控制 */
animation-play-state: running;
}
@keyframes moveAnim {
0% {
transform: translate(0, 0) scale(0.5);
}
33% {
transform: translate(0, 200px) scale(1.2);
}
66% {
transform: translate(400px, 200px) scale(1);
}
100% {
transform: translate(400px, 0) scale(0.5);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: orange;
/* animation-name: moveAnim;
animation-duration: 3s;
animation-timing-function: ease-in-out;
animation-delay: 2s;
animation-iteration-count: 2;
animation-direction: reverse;
animation-fill-mode: backwards;
animation-play-state: running; */
/* animation: name duration timing-function delay iteration-count direction fill-mode; */
animation: moveAnim 3s ease-in-out 2s 2 reverse backwards;
}
@keyframes moveAnim {
0% {
transform: translate(0, 0) scale(0.5);
}
33% {
transform: translate(0, 200px) scale(1.2);
}
66% {
transform: translate(400px, 200px) scale(1);
}
100% {
transform: translate(400px, 0) scale(0.5);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
行盒
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.small {
display: inline-block;
width: 100px;
height: 100px;
background-color: #f00;
}
</style>
</head>
<body>
<div class="box">
我是div元素<span class="small"></span> ipsum dolor, sit amet consectetur
adipisicing elit. Sed laborum libero numquam! Unde error temporibus,
adipisci voluptatem, assumenda, illum quo exercitationem beatae facere
expedita tempora mollitia nemo autem fuga non?
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.small {
display: inline-block;
width: 100px;
height: 100px;
background-color: #f00;
}
</style>
</head>
<body>
<div class="box">
我是div元素<span class="small">123</span> ipsum dolor, sit amet consectetur
adipisicing elit. Sed laborum libero numquam! Unde error temporibus,
adipisci voluptatem, assumenda, illum quo exercitationem beatae facere
expedita tempora mollitia nemo autem fuga non?
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
vertical-align: top;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
}
.box .small {
width: 100px;
height: 200px;
display: inline-block;
background-color: #f00;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
<span class="small"></span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
}
.box .small {
width: 100px;
height: 200px;
display: inline-block;
background-color: #f00;
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
<span class="small"></span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
}
.box .small {
width: 100px;
height: 200px;
display: inline-block;
background-color: #f00;
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
<span class="small">aaa</span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
</style>
</head>
<body>
<div class="box">
<img src="./images/kobe01.jpg" alt="" />
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
</style>
</head>
<body>
<div class="box"><img src="./images/kobe01.jpg" alt="" />dnf</div>
</body>
</html>
vertical-align
- 默认值
- baseline
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
vertical-align: middle;
}
.box .small {
width: 100px;
height: 200px;
display: inline-block;
background-color: #f00;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
<span class="small"></span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
vertical-align: top;
}
</style>
</head>
<body>
<div class="box"><img src="./images/kobe01.jpg" alt="" />dnf</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
vertical-align: middle;
}
</style>
</head>
<body>
<div class="box"><img src="./images/kobe01.jpg" alt="" />dnf</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
vertical-align: bottom;
}
</style>
</head>
<body>
<div class="box"><img src="./images/kobe01.jpg" alt="" />dnf</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
display: block;
}
</style>
</head>
<body>
<div class="box"><img src="./images/kobe01.jpg" alt="" /></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
background-color: orange;
}
.box img {
width: 200px;
vertical-align: middle;
}
.box .small {
width: 100px;
height: 200px;
display: inline-block;
background-color: #f00;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="box">
我是普通的文本,dfjsdjf
<img src="./images/kobe01.jpg" alt="" />
<span class="small">理解快递费静安寺福建烤老鼠佳都科技塑料袋减肥j</span>
</div>
</body>
</html>
内容回顾
一、transform
1.1.transform作用以及语法
1.2.translate(x, y)
1.3.translate的百分比(总结垂直居中的方案)
- 利用百分比做垂直居中
1.4.scale(x, y)
1.5.rotate(x, y)
- deg
- 正值
- 顺时针
- 负值
- 逆时针
- 正值
- rad
1.6.transform-origin
- 修改形变的坐标原点
1.7.skew倾斜
- deg
1.8.transform设置多个值
二、transition
2.1.理解过渡动画
- 哪些是可执行动画的属性
2.2.过渡常见属性
- transition-property
- transition-duration
- transition-timing-function
- transition-delay
2.4.总结几个单词的作用
- transform
- translate
- transition
三、animation
3.1.transition弊端和animation介绍
3.2.animation的使用过程
- @keyframes 定义每一帧的属性
- animation属性
- animation-name
- animation-duration
- animation-timing-function
- animation-delay
- animation-iteration-count
- animation-direction
- animation-fill-mode
- animation-play-state