我想請教一下: # 31行 ,我沒有給 a 和 a的父級寬度,而 a 已變成塊級元素。---塊級元素如果沒有寬度,默認是和父級一樣寬。
只有行內或行內塊元素,寬度才會由內容撐開。---但是為啥這些 a 已是塊級元素,還是寬度根據內容來撐開?
謝謝大佬。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box1 {
float: left;
width: 209px;
height: 45px;
background-color: pink;
}
.box2 {
float: left;
}
li {
float: left;
list-style: none;
}
.box a {
display: block;
height: 45px;
line-height: 45px;
padding: 0 30px;
border: 1px solid #000;
background-color: skyblue;
}
</style>
</head>
<body>
<div class="box">
<div class="box1"></div>
<div class="box2">
<ul>
<li>
<a href="https://bbs.csdn.net/topics/#">123</a>
</li>
<li>
<a href="https://bbs.csdn.net/topics/#">123aaaa</a>
</li>
<li>
<a href="https://bbs.csdn.net/topics/#">123bbbbb</a>
</li>
</ul>
</div>
</div>
</body>
</html>
uj5u.com熱心網友回復:
.box a {display: block;
width: 500px;
/* 塊級元素需要設定寬 */
}
給你一個參考的地址
http://www.xinbiancheng.cn/css/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/251275.html
標籤:HTML(CSS)
上一篇:前端匯入依賴失敗的問題
