0
点赞
收藏
分享

微信扫一扫

【前端学习笔记 CSS系列二】整体布局训练

忍禁 2022-02-12 阅读 51

一、效果

在这里插入图片描述

二、代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>css布局训练-一列固定宽度且居中</title>
		<style>
			*{
				padding: 0;
				margin: 0;
			}
			/* 采用并集选择器简化代码 */
			.top,
			.banner,
			.main,
			.footer {
				width: 960px;
				text-align: center;
				/* text-align让文字居中显示 */
				margin: 0 auto;
				/* margin让盒子居中对齐,只要左右auto就可以了 */
				margin-bottom: 10px;
				border: 1px dashed #ccc;
			}
			.top {
				height: 80px;
				background-color: pink;
			}
			.banner {
				height: 120px;
				background-color: purple;
			}
			.main {
				height: 500px;
				background-color: hotpink;
			}
			.footer {
				height: 150px;
				background-color: black;
			}
			
		</style>
	</head>
	<body>
		<div class="top">top</div>
		<div class="banner">banner</div>
		<div class="main">main</div>
		<div class="footer">footer</div>
	</body>
</html>

举报

相关推荐

0 条评论