亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么沒有水平居中顯示?

<!DOCTYPE HTML>
<html>
<head>
? ?<meta charset="utf-8">
? ?<style type="text/css">
? ? div{
? ? ? ? border:2px solid red;
? ? ? ? width:500px;
? ? ? ? margin:10px auto;
? ? ? ? height:100px;
? ? ? ? line-height:100px;
? ? }
? ?</style>
? ?<title>定寬居中</title>
</head>
<body>
<div>i want to be in the middle.</div>
</body>
</html>

http://img1.sycdn.imooc.com//5875e2c20001a89c19201080.jpg

正在回答

1 回答

你設置的margin:10px auto;代碼代表的是塊狀元素的居中(div 邊框 截圖中紅色邊框確實實現了居中)

文字屬于行內元素,因此居中應該設置為 text-align:center

<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>定寬居中</title>
? ?<style type="text/css">
div{
? ? ? ? ? ?border:2px solid red;
width:500px;
margin:10px auto;
height:100px;
line-height:100px;
}
? ? ? ?.textCenter{
? ? ? ? ? ?text-align: center;

}
? ?</style>
</head>
<body>
? ?<div class="textCenter">i want to be in the middle.</div>
</body>
</html>

0 回復 有任何疑惑可以回復我~
#1

TicoM 提問者

非常感謝!
2017-01-11 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么沒有水平居中顯示?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號