一、背景(background)
1.background-size
背景大小:水平 垂直
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrap {
width: 300px;
height: 200px;
border: 1px solid black;
background: url(img/baby0.jpg) no-repeat;
margin: 100px auto;
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
</html>
2.background-origin
原点/起始点:
background-origin:border-box(以边框为起始点);
background-origin:content-box(以内容为起始点);
background-origin:padding-box(以内边距为起始点).
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrap {
width: 500px;
height: 500px;
border: 20px solid rgba(0,0,255,0.2);
background: url(img/baby0.jpg) no-repeat;
background-origin: border-box;
margin: 100px auto;
padding: 30px;
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
</html>
3.background-clip
背景裁剪:
background-clip:border-box(以边框裁剪);
background-clip:content-box(以内容裁剪);
background-clip:padding-box(以内边距裁剪);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrap {
width: 500px;
height: 500px;
border: 35px solid rgba(0,0,255,0.3);
margin: 100px auto;
background: url(img/baby0.jpg) no-repeat;
background-clip: content-box;
padding: 35px;
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
</html>
4.多背景
background:url() left top no-repeat,right top no-repeat, left bottom no-repeat,right bottom no-repeat;
background:url() no-repeat center center;居中
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrap {
width: 623px;
height: 417px;
border: 1px solid black;
background: url(img/bg1.png) no-repeat left top,
url(img/bg2.png) no-repeat right top,
url(img/bg3.png) no-repeat right bottom,
url(img/bg4.png) no-repeat left bottom,
url(img/bg5.png) no-repeat center center;
margin: 100px auto;
line-height: 400px;
text-align: center;
font-family: "微软雅黑";
color: blueviolet;
font-size: 40px;
font-weight: 900;
}
</style>
</head>
<body>
<div class="wrap">好好学习!</div>
</body>
</html>
二、渐变
1.线性渐变
background:linear-gradient(to left,yellow,green);
to left:渐变方向 值2:颜色
background:linear-gradient(45deg,yellow,green);
值1:渐变角度 值2:颜色
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
div {
width: 1000px;
height: 100px;
border: 1px solid black;
margin: 0 auto;
margin-top: 20px;
}
.div1 {
background: linear-gradient(to left,yellow,green);
}
.div2 {
height: 300px;
background: linear-gradient(to left,green,yellow);
}
.div3 {
background: linear-gradient(90deg,yellow,pink,blue,red);
}
.div4 {
background: linear-gradient(135deg,
black 0%,
black 25%,
yellow 25%,
yellow 50%,
green 50%,
green 75%,
red 75%,
red 100%);
}
.div5 {
background: linear-gradient(135deg,
#000 0%,
#000 25%,
#fff 25%,
#fff 50%,
#000 50%,
#000 75%,
#fff 75%,
#fff 100%
);
background-size: 100px 100px;
animation: move 1s linear infinite;
}
@keyframes move{
from{
background-position: 0px 0px;
}
to{
background-position: 100px 0px;
}
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
<div class="div5"></div>
</body>
</html>
2.径向渐变
background:radial-gradient(at center,yellow,green);
at:关键词 center:中心点/起始点 值2:颜色
background:radial-gradient(at 50px 50px,yellow,green);
50px 50px:距离水平50像素,垂直50像素的距离。
background:radial-gradient(100px 50px at center,yellow,green);中心显示椭圆
100px 50px:由中心点向外辐射的范围
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
div {
width: 200px;
height: 200px;
border: 1px solid black;
float: left;
margin-top: 60px;
margin-right: 40px;
}
.div1 {
background: radial-gradient(at center,yellow,green);
}
.div2 {
background: radial-gradient(at left top,yellow,green);
}
.div3 {
background: radial-gradient(at 50px 50px,yellow 0%,pink 30%,green 60%,red 100%);
}
.div4 {
background: radial-gradient(100px 50px at center,yellow,green);
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
</body>
</html>
三、过渡
transiation:param1,param2;
param1:过度的属性
param2:过度的时间
简便方式:transiation:all 3s;
all表示该元素所有属性。
可分开写:transiation-property:left;过渡的属性
transiation-duration:2s;过渡的时间
设置过渡的速度:
transiation-timing-function:linear(匀速/线性过渡)/ease(平滑过渡)/ease-in(加速/由慢到快)/
ease-out(由慢到快)/ease-in-out(由慢到快再到慢)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrap {
width: 200px;
height: 200px;
border: 1px solid black;
background: green;
position: relative;
left: 0;
top: 0;
transition: left 1s,top 1s;
}
.wrap:hover {
left: 200px;
top: 200px;
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
</html>
四、2D变换
都可从X、Y方向缩放、扭曲、旋转、位移
属性:transform:scale(x,y); 缩放倍数 (x,y)可为小数,不可为负数
transform:skew(45deg); 扭曲 单位为角度
transform:rotate(45deg); 旋转 单位为角度
设置旋转的中心点:transform-origin:center bottom;
transform:tranlate(x,y); 位移 x表示水平位移 y表示垂直位移
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.wrap {
width: 300px;
height: 300px;
background: red;
margin: 150px auto;
transition: all 0.5s;
}
.wrap:hover {
background: purple;
border-radius: 50%;
transform: rotate(360deg);
}
</style>
</head>
<body>
<div class="wrap"></div>
</body>
</html>