CSS布局 通栏平均分布型

本文探讨了如何使用CSS实现网页布局中通栏元素的平均分布,包括使用 Flexbox 和 Grid 布局的方法,以及浏览器兼容性和最佳实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>通栏平均分布型</title>
	<style>
	* {
		margin: 0;
		padding: 0;
	}
	.top {
		/* 通栏的盒子 可以不用写宽度 默认的宽度和浏览器一样宽 */
		height: 80px;
		border: 1px dashed #aaa;
		background-color: #eee;
		text-align: center;
	}
	.banner {
		width: 960px;
		height: 150px;
		border: 1px dashed #aaa;
		background-color: #eee;
		text-align: center;
		margin: 8px auto;
	}
	.small {
		margin-bottom: 10px;
		width: 960px;
		height: 100px;
		/* border: 1px dashed #aaa;
		background-color: gray; */
		text-align: center;
		margin: 8px auto;
	}
	ul {
		list-style: none;
	}
	.small ul li {
		width: 230px;
		border: 1px dashed #aaa;
		background-color: #eee;
		height: 100px;
		float: left;
		margin-left: 10px;
	}
	.small ul .nomargin {  /* 注意: 必须加权重 */
		margin-left: 0;
	}
	.footer {
		height: 150px;
		border: 1px dashed #aaa;
		background-color: #eee;
		margin-top: 10px;
	}
	</style>
</head>
<body>
	<div class="top">顶部通栏</div>
	<div class="banner">banner</div>
	<div class="small">
	<ul>
		<li class="nomargin">1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
	</ul>
	</div>

	<div class="small">
	<ul>
		<li class="nomargin">1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
	</ul>
	</div>
	<div class="small">
	<ul>
		<li class="nomargin">1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
	</ul>
	</div>
	<div class="footer"></div>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值