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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

html布局中怎么會出現一條空隙

html布局中怎么會出現一條空隙

江戶川亂折騰 2019-05-16 15:10:25
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><style type="text/css">#menu {background-color:#ffff99;height:200px; float:left;width:100px;margin-top:0px;}h2 {margin-bottom:0px; font-size:14px;}#container{width:500px;}h1{margin-bottom:0px;text-decoration:0px;font-family:Georgia, "Times New Roman", Times, serif;font-size:40px;color:#90DA11;}#content{float:right;background-color:#6FF;width:400px;height:200px;}#footer{background-color:#6F3;clear:both;text-align:center;}p{line-height:0px;margin-top:5px;text-indent:20px;color:#000;font-family:Arial, Helvetica, sans-serif;font-weight:bolder;}#header{margin-bottom:0px;}</style></head><body><div id = "container"><div id="header"><h1>智慧教室</h1><p>Smart Classroom</p></div><div id="menu"><h2>Menu</h2><ul><li>HTML</li><li>CSS</li><li>JavaScript</li></ul></div><div id="content" ></div><div id="footer">Copyright W3School.com.cn</div></div></body></html>
查看完整描述

2 回答

?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

1

2

3

4

5

6

7

8

p{

    line-height:20px;

    margin:0;

    text-indent:20px;

    color:#000;

    font-family:Arial, Helvetica, sans-serif;

    font-weight:bolder;

}

<p>標簽是帶有默認樣式的,這一點你必須要知道。

首先,你在<h1>標簽下方使用了該標簽,而后,你讓P標簽的line-height為零,這是不合理的,要知道,line-height表示你的這個標簽中文字垂直占位,這個數字要合理,比如你這里,你可以使用20px;

而p標簽還帶有margin-top和margin-bottom的默認樣式,你已經讓p標簽的margin-top為5px了,那么這個空隙,就是margin-bottom帶來的。

所以,要讓你的p標簽沒有那個所謂的空隙,就要加上margin-bottom:0;或者是在定義margin-top之前,定義margin:0;都可以。

P標簽樣式修改后為上面代碼框中的樣式。

 




查看完整回答
反對 回復 2019-05-17
?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊


HTML中有縫隙出現的原因有很多:

  1. 表格:有表格空間,因此在不需要它們之間有縫隙的時候最好加上一句{border-spacing: 0;};

  2. 瀏覽器自帶的外邊距、內邊距。因為不同的瀏覽器,這個屬性默認的可能不同,因此,在編寫樣式之前,加上*{padding:0;margin:0;},清楚瀏覽器之間的差異;

  3. 布局錯誤,比如:

    1. 用了浮動卻沒有清除浮動,父級因此脫離文檔流,布局錯亂也有可能出現空隙;

    2. 多余的標簽,不需要這個標簽卻又在布局中添加了,并且這個標簽有了一些樣式,比如內邊距,或者border之類的撐起空間的。那么也會出現空隙




查看完整回答
反對 回復 2019-05-17
  • 2 回答
  • 0 關注
  • 308 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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