目录
CSS Sprites的原理 (图片整合技术)(CSS精灵)/雪碧图
0087 锚点
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
position: fixed;
right: 0;
top: 100px;
}
li{
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid black;
}
div{
height: 600px;
border: 1px solid #cccccc;
}
/* 锚点作用:页面不同区域的跳转,使用a链接
<a href="#锚点名字"></a>
<div id="锚点名字"></div>
*/
</style>
</head>
<body>
<ul>
<li><a href="#a">京东秒杀</a></li>
<li><a href="#b">双11</a></li>
<li><a href="#c">频道优选</a></li>
<li><a href="#d">特色广场</a></li>
</ul>
<div id="a">
京东秒杀
</div>
<div id="b">
双11
</div>
<div id="c">
频道优选
</div>
<div id="d">
特色广场
</div>
</body>
</html>
0088 精灵图
CSS Sprites的原理 (图片整合技术)(CSS精灵)/雪碧图
- 将导航背景图片,按钮背景图片等有规则的合并成一张背景图,即将多张图片合为一张整图,然后用background-position”来实现背景图片的定位技术。
-
图片整合的优势:
- 通过图片整合来减少对服务器的请求次数,从而提高页面的加载速度
- 通过整合图片来减小图片的体积
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
div{
width: 103px;
height: 32px;
float: left;
margin: 10px;
background: yellow url(图片路径);
}
.box1{
background-position: -205px -111px;
}
.box2{
background-position: -205px -74px;
}
.box3{
background-position: -205px -37px;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<div class="box5"></div>
<div class="box6"></div>
</body>
</html>
0089 宽高自适应
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
/* width: 100px; */
width: auto;/* 不写或auto即为自适应 */
/* width: 100%; */
height: 100px;
padding-left: 100px;
background: yellow;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.header,.footer{
width: 100%;
height: 50px;
background: yellow;
}
.body{
min-height: 500px;
background: red;
}
li{
height: 100px;
}
/*
min-height 最小高度
max-height
min-width
max-width
*/
</style>
</head>
<body>
<div class="header"></div>
<div class="body">
<ul>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
</ul>
</div>
<div class="footer"></div>
</body>
</html>
示例代码3:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.header,.footer{
width: 100%;
height: 50px;
background: yellow;
}
.body{
min-height: 500px;
background: red;
}
li{
height: 100px;
max-width: 500px;
margin: 0 auto;
background: blue;
}
/*
min-height 最小高度
max-height
min-width
max-width
*/
</style>
</head>
<body>
<div class="header"></div>
<div class="body">
<ul>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
<li>111111111</li>
</ul>
</div>
<div class="footer"></div>
</body>
</html>
0090 浮动元素之父元素高度自适应1
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
.left,.right{
width: 100px;
height: 100px;
float: left;
}
.left{
background: yellow;
}
.right{
background: red;
}
.content{
width: 200px;
height: 200px;
background: green;
}
/* .box{
height: 100px;/* 如果浮动过多,换行就出现问题 */
} */
.box{
overflow: hidden;
}
</style>
</head>
<body>
<div class="box">
<div class="left"></div>
<div class="right"></div>
<!-- <div style="clear: both;"></div> -->
<!-- 2. 增加空标签,不利于代码可读性 -->
</div>
<div class="content"></div>
</body>
</html>
0091 浮动元素之父元素高度自适应2
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
/* 伪元素 */
div::first-letter{
font-size: 30px;
color: red;
}
div::first-line{
/* font-size: 30px; */
background: yellow;
}
div::before{
content: "aaaaa";
}
div::after{
content: "bbbbbb";
}
</style>
</head>
<body>
<div>
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Voluptatibus quod officiis vel delectus nesciunt consectetur
obcaecati, odit vitae repellat quaerat iste quidem illum quos
assumenda consequuntur placeat omnis ab blanditiis.
</div>
</body>
</html>
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
.box1{
width: 100px;
height: 100px;
background: yellow;
/* display: none; */
/* 不占位的隐藏 */
visibility: hidden;
/* 占位隐藏 */
}
.box2{
width: 100px;
height: 100px;
background: red;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
0092 窗口自适应
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 100%;
height: 100%;
background: yellow;
}
html,body{
height: 100%;
}
.child1{
background: blue;
height: 50%;
}
.child2{
background: red;
height: 50%;
}
</style>
</head>
<body>
<div class="box">
<div class="child1"></div>
<div class="child2"></div>
</div>
</body>
</html>
0093 两栏布局
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.box1{
width: 200px;
height: 100%;
background: red;
float: left;
}
.box2{
height: 100%;
background: yellow;
margin-left: 200px;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.box1{
width: 200px;
height: 100%;
background: red;
float: left;
}
.box2{
width: calc(100% - 200px);
height: 100%;
background: yellow;
/* margin-left: 200px; */
float: left;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
0094 三栏布局
示例代码1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.left,.right{
width: 200px;
height: 100%;
}
.left{
background: yellow;
float: left;
}
.right{
background: red;
float: right;
}
.center{
height: 100%;
background: blue;
margin-left: 200px;
margin-right: 200px;
}
</style>
</head>
<body>
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</body>
</html>
示例代码2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.left,.right{
width: 200px;
height: 100%;
}
.left{
background: yellow;
float: left;
}
.right{
background: red;
float: right;
}
.center{
width: calc(100% - 400px);
height: 100%;
background: blue;
float: left;
}
</style>
</head>
<body>
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</body>
</html>
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.top,.bottom{
width: 100%;
height: 50px;
background: grey;
}
.middle{
height: calc(100% - 100px);
background: yellow;
}
.left,.right{
width: 100px;
height: 100px;
background: red;
float: left;
}
.center{
width: calc(100% - 200px);
height: 100%;
background: blue;
float: left;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="middle">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
<div class="bottom"></div>
</body>
</html>