第一部分 网页修饰

本文介绍了CSSSprites(雪碧图)的原理与应用,探讨了宽度自适应、浮动元素下父元素高度自适应的方法,以及如何实现窗口自适应和常见的两栏、三栏布局示例。通过HTML和CSS代码展示,帮助开发者提升页面性能和布局效果。
摘要由CSDN通过智能技术生成

目录

0087 锚点

示例代码:

0088 精灵图

CSS Sprites的原理 (图片整合技术)(CSS精灵)/雪碧图

图片整合的优势:

示例代码:

0089 宽高自适应

示例代码1:

示例代码2:

示例代码3:

0090 浮动元素之父元素高度自适应1

示例代码:

0091 浮动元素之父元素高度自适应2

示例代码:

示例代码:

0092 窗口自适应

示例代码:

0093 两栏布局

示例代码1:

示例代码2:

0094 三栏布局

示例代码1:

示例代码2:

示例代码:


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”来实现背景图片的定位技术。
  • 图片整合的优势:

  1. 通过图片整合来减少对服务器的请求次数,从而提高页面的加载速度
  2. 通过整合图片来减小图片的体积
示例代码:
<!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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值