非布局样式-背景
知识点
背景颜色
hsla(60,100%,50%) 四个参数: 颜色(0-360)、饱和度、亮度、透明度
hsl()可以不设透明度
渐变色背景
background: -webkit-linear-gradient(left, red, green);
background: linear-gradient(to right, red, green);
线性渐变
demo1里第一个参数为XXdeg的是角度
还可以做多色渐变,见demo1
多背景叠加
background: linear-gradient(135deg, transparent 0, transparent 49.5%, green 49.5%, green 50.5%, transparent 50.5%, transparent 100%),
linear-gradient(45deg, transparent 0, transparent 49.5%, red 49.5%, red 50.5%, transparent 50.5%, transparent 100%);
background-size: 30px 30px;
第一行代码就像在50的地方画了一条绿线,background-size设成30*30,就会直接平铺,第二行代码是反方向画线,最后效果是一条网格线
背景图片和属性(雪碧图:不同素材基础到一张图里)
背景图位置、大小、平铺方式见demo2的c1,
雪碧图: 希望把多个图标放在一个图里。雪碧图是重点,要懂原理和实现
base64和性能优化
文本代表图片本身,可以自己做base64转换器。图片转base64, 体积变原本的4/3,节省a链接数,但是文件体积增大,图片增大1/3,图片放到了css文件中,因此只适用于小图标,少量,减少了http请求数,增大了体积的开销,增大了解码的开销。
多分辨率适配
两倍图,三倍图
demo1
<!DOCTYPE html>
<html>
<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>background</title>
<style>
body{
background:yellow;
}
.c1{
height:90px;
/* background:rgba(255,0,0, .3); */
/* background:url(./test.png); */
}
.c2{
height:90px;
/* background: -webkit-linear-gradient(left, red, green); */
/* background: linear-gradient(to right, red, green); */
/* background: linear-gradient(180deg, red, green); */
/* background: linear-gradient(135deg, red 0, green 10%, yellow 50%, blue 100%); */
background: linear-gradient(135deg, transparent 0, transparent 49.5%, green 49.5%, green 50.5%, transparent 50.5%, transparent 100%),
linear-gradient(45deg, transparent 0, transparent 49.5%, red 49.5%, red 50.5%, transparent 50.5%, transparent 100%);
background-size: 30px 30px;
}
</style>
</head>
<body>
<div class="c1">
</div>
<div class="c2">
</div>
</body>
</html>
demo2
<!DOCTYPE html>
<html>
<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>background</title>
<style>
.c1{
height:900px;
background:red url(/test.png);//找个png图放在同一目录下,命名test
background-repeat: no-repeat;
/* background-position: center top; */
/* background-position: 20px 30px; */
/* background-size:100px 50px; */
}
.c2{
width:20px;
height:20px;
background:url(./test_bg.png) no-repeat;
background-position: -17px -5px;
background-size: 261px 113px;
}
.c3{
width:20px;
height:20px;
background:url(./test_bg.png) no-repeat;
background-position: -169px -23px;
background-size: 261px 113px;
}
</style>
</head>
<body>
<div class="c1">
</div>
<div class="c2">
</div>
<div class="c3">
</div>
</body>
</html>
非布局样式-边框
知识点
边框的属性:线型 大小 颜色
见demo3 c1
边框背景图
见demo3 c2 真实场景不大用
边框衔接(三角形)斜切的衔接
见demo3 c3
c3的width=1px的时候就是个三角形
demo3
<!DOCTYPE html>
<html>
<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>border</title>
<style>
.c1{
width:400px;
height: 200px;
/* border: 1px solid red; */
/* border:5px solid red; */
/* border:5px dotted red; */
border:5px dashed red;
}
.c2{
width:400px;
height: 200px;
/* border-width: 30px; */
border:30px solid transparent;
border-image:url(./border.png) 30 round;
}
.c3{
width:400px;
height: 200px;
border-bottom:30px solid red;
/* border-right:30px solid blue; */
border-left:30px solid transparent;
border-right:30px solid transparent;
}
</style>
</head>
<body>
<div class="c1">
</div>
<div class="c2">
</div>
<div class="c3">
</div>
</body>
</html>