首页
/
每日頭條
/
職場
/
html怎麼設置div裡的div居中
html怎麼設置div裡的div居中
更新时间:2025-12-14 16:22:16

水平居中:給div設置一個寬度,然後添加margin:0 auto;屬性。

div{ width:200px; margin:0 auto; }

絕對定位的div居中:

div { position: absolute; width: 300px; height: 300px; margin: auto; top: 0; left: 0; bottom: 0; right: 0; background-color: pink; /* 方便看效果 */ }

html怎麼設置div裡的div居中(面試基礎12如何居中一個div)1

水平垂直居中一:

html怎麼設置div裡的div居中(面試基礎12如何居中一個div)2

水平垂直居中二:

html怎麼設置div裡的div居中(面試基礎12如何居中一個div)3

水平垂直居中三:

html怎麼設置div裡的div居中(面試基礎12如何居中一個div)4

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved