flex布局实现盒子居中

示例代码如下:

<!-- css -->
<style>
	body {
		margin: 0;
		padding: 0;
	}
	.main {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 600px;
		width: 600px;
		background-color: #ccc;
	}
	.item {
		height: 100px;
		width: 100px;
		background-color: #ff5;
	}
</style>
<!-- html -->
<body>
	<div class="main">
		<div class="item">
		</div>
	</div>
</body>
posted @ 2021-03-29 11:40  程序员陈师兄cxycsx  阅读(995)  评论(0)    收藏  举报