<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box{
display: flex;
justify-content: center;
align-items: center;
width: 200px;
height: 200px;
background-color: #222;
}
.item{
width: 20px;
height: 20px;
background-color: #f00;
}
</style>
</head>
<div class="box">
<span class="item"></span>
</div>
</body>
</html>
本文介绍了一个简单的HTML页面,使用CSS的Flex布局来实现居中显示的功能。通过定义一个名为.box的容器类,并设置display为flex,justify-content和align-items均为center,实现了内部元素的水平垂直居中。此外,还定义了一个名为.item的类来展示居中效果。

706

被折叠的 条评论
为什么被折叠?



