<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>flex的居中显示</title> <STYLE> #DIV1{ width: 200px; height: 200px; background-color: red; display: flex; justify-content:center; align-items: center; } #DIV2{ width: 100px; height: 100px; background-color: yellow; } </STYLE> </head> <body> <div ID="DIV1"> <div ID="DIV2"></div> </div> </body> </html>
本文通过一个简单的HTML示例展示了如何使用Flex布局实现元素的水平和垂直居中。通过设置display为flex,并结合justify-content与align-items属性,可以轻松地使内部元素在父容器中居中显示。
1234

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



