CSS中页面的布局案例-利用浮动

(接期末课程设计题目,支持定制)

利用浮动完成页面布局

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			
			/*清除默认样式*/
			*{
				margin: 0;
				padding: 0;
			}
			
			/*设置头部div*/
			.header{
				/*设置一个宽度*/
				width: 1000px;
				/*设置一个高度*/
				height: 120px;
				/*设置一个背景颜色*/
				background-color: yellowgreen;
				/*设置居中*/
				margin: 0 auto;
			}
			
			/*设置一个content*/
			.content{
				/*设置一个宽度*/
				width: 1000px;
				/*设置一个高度*/
				height: 400px;
				/*设置一个背景颜色*/
				background-color: orange;
				/*居中*/
				margin: 10px auto;
			}
			
			/*设置content中小div的样式*/
			.left{
				width: 200px;
				height: 100%;
				background-color: skyblue;
				/*向左浮动*/
				float: left;
			}
			
			.center{
				width: 580px;
				height: 100%;
				background-color: yellow;
				/*向左浮动*/
				float: left;
				/*设置水平外边距*/
				margin: 0 10px;
			}
			
			.right{
				width: 200px;
				height: 100%;
				background-color: pink;
				/*向左浮动*/
				float: left;
			}
			
			
			
			/*设置一个footer*/
			.footer{
				/*设置一个宽度*/
				width: 1000px;
				/*设置一个高度*/
				height: 120px;
				/*设置一个背景颜色*/
				background-color: silver;
				/*居中*/
				margin: 0 auto;
			}
			
		</style>
	</head>
	<body>
		<!-- 头部div -->
		<div class="header"></div>
		
		<!-- 主体内容div -->
		<div class="content">
			<!-- 左侧div -->
			<div class="left"></div>
			<!-- 中间div -->
			<div class="center"></div>
			<!-- 右侧div -->
			<div class="right"></div>
			
		</div>
		
		<!-- 底部信息div -->
		<div class="footer"></div>
		
	</body>
</html>
相关推荐
岱宗夫up3 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
紫陌涵光3 小时前
112. 路径总和
java·前端·算法
漠月瑾-西安3 小时前
CVE-2025-55182漏洞解析:你的React项目安全吗?
前端·安全·react.js
No丶slovenly3 小时前
flutter笔记-输入框
前端·笔记·flutter
国产化创客4 小时前
ESP32+Web实现智能气象站
前端·物联网·智能家居·智能硬件
coderYYY5 小时前
VSCode终端启动报错
前端·ide·vscode·npm·编辑器
tod1135 小时前
Redis 数据类型与 C++ 客户端实践指南(redis-plus-plus)
前端·c++·redis·bootstrap·html
Sylvia33.5 小时前
火星数据:棒球数据API
java·前端·人工智能
weixin199701080166 小时前
1688商品详情页前端性能优化实战
前端·性能优化
DEMO派6 小时前
前端常用XSS攻击演示与防御方案解析
前端·xss