4 回答

TA貢獻76條經驗 獲得超19個贊
因為a標簽是屬于行內元素,行內元素是無法設置寬和高的,即使設置了也不起作用,那么把它設置成display:inline-block后,也就是把它設置成了行內塊狀元素,那么它同時擁有行內元素和塊狀元素的特點,就可以設置寬、高等屬性了!
刪除display:inline-block有沒有影響要看你有沒給a標簽設置寬高等屬性,如果沒設置這些屬性當然就沒有影響了!
下面這段代碼你運行一下,試著把display:inline-block注示掉,就知道它們的區別在哪了,希望能幫到你,加油?。?!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<style type="text/css">
? ? .imooc{
? ? background-color:red;
? ? }
? ? #imooc2{
? ? ? ? display:inline-block;
? ? ? ? width:100px;
? ? ? ? height:25px;
? ? ? ? text-align:center;
? ? ? ? line-height:25px;
? ? }
</style>
</head>
<body>
? ? <a class="imooc" id="imooc1" href="#">慕課網</a>
? ? <a class="imooc" id="imooc2" href="#">慕課網</a>
</body>
</html>
- 4 回答
- 1 關注
- 4877 瀏覽
相關問題推薦
添加回答
舉報