CSS水平置中

問題

要讓某元素置於螢幕畫面中間

方法

margin-left: auto;
margin-right: auto;

範例

<div>置中</div>
div{
 width: 350px;
 height: 200px;
 padding: 20px;
 margin-left: auto;
 margin-right: auto;
 border: solid 1px #ccc;
 text-align: center;
}

Display

置中

Leave a Reply

Your email address will not be published. Required fields are marked *