HTML——左侧边栏布局



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>上中下布局</title>
		<style type="text/css">
			body{
				background: #42413C ;
				margin: 0;/*消除body中的留白*/
				padding: 0;
				text-align: center;
			}
			
			.container{
				width: 778px;
				background: #FFF;
				margin: 0 auto;/*侧边的自动值与宽度结合使用,可以将布局居中对齐*/
				text-align: left;
			}
			
			.header{
				padding: 10px 0;
				background: #ADB96E;
			}
			
			.sidebar{
				float: left;/*侧边栏居左,改为right可令侧边栏居右*/
				width: 200px;
				background: #a4f;
			}
			
			.maincontent{
				width: 570px;
				background: #eee;
			}
			
			.footer{
				clear: both;/*清除前后的浮动元素,使页脚显示在其下方*/
				position: relative;/*修改IE浏览器中clear无效的bug*/
				padding: 10px 0;
				background: #CCC49F;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="header">
				<h1>网页头部</h1>
			</div>
			
			<div class="content">
				<div class="sidebar">
					<h1>侧边栏</h1>
					<h1>侧边栏</h1>
					<h1>侧边栏</h1>
				</div>
				<div class="maincontent">
					<h1>网页正文</h1>
					<h1>网页正文</h1>
					<h1>网页正文</h1>
					<h1>网页正文</h1>
					<h1>网页正文</h1>
					<h1>网页正文</h1>
				</div>
			</div>
			<div class="footer">
				<h1>脚注</h1>
			</div>
		</div>
	</body>
</html>







HTML中,网页顶部和侧边栏的设计通常涉及固定布局(fixed layout)或响应式布局(responsive design)。这里简单介绍一下基本结构: **固定布局**: ```html <!DOCTYPE html> <html> <head> <style> .header { position: fixed; /* 将头部设为固定位置 */ top: 0; width: 100%; background-color: #f8f9fa; } .sidebar { position: fixed; top: 60px; /* 避免与头部重叠,假设头部高度为60px */ left: 0; width: 200px; height: 100%; /* 全屏高度 */ background-color: #f5f5f5; } .main-content { margin-left: 200px; /* 让主要内容区避开侧栏宽度 */ } </style> </head> <body> <div class="header">头部内容</div> <div class="sidebar">侧边栏内容</div> <div class="main-content">主体主要内容区域</div> </body> </html> ``` **响应式布局** (使用Bootstrap等框架): ```html <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> </head> <body> <nav class="navbar navbar-expand-lg bg-light"> <!--头部内容--> </nav> <div class="col-md-2 sidebar bg-light">侧边栏内容</div> <div class="col-md-10 main-content">主体主要内容区域</div> </body> </html> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值