首页
CSS
CSS 外边距
试用:使用 margin: auto
运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <head> <style> div { width: 300px; margin: auto; border: 1px solid red; } </style> </head> <body> <h2>Use of margin: auto</h2> <p>You can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins:</p> <div> This div will be horizontally centered because it has margin: auto; </div> </body> </html>