CSS 中使用 auto 值的 margin 属性的作用
值为 auto 的 margin 属性用于在其容器内水平居中元素。您可以尝试运行以下代码来实现 margin: auto;
示例
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 200px;
margin: auto;
border: 2px dashed blue;
}
</style>
</head>
<body>
<p>This is demo text</p>
<div>
This is horizontally centered because it has margin: auto;
</div>
</body>
</html>输出

广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP