2014-02-16 16 views
0

如果您運行以下代碼,您會注意到單詞hello以每個新行之間有較大距離的白色div垂直輸出。我已經嘗試了許多不同的東西,例如擺脫邊緣風格(不知道它是否重要),但沒有找到解決方案的運氣。我的文本在div中每個新行之間有很大的垂直空間?

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=windows-1252"> 
<title>div_experiment</title> 
</head> 
<body> 
<style type = "text/css"> 
body 
{ 
    background-color: black; 
} 
#div_id 
{ 
    position: absolute; 
    top: 0%; 
    left: 50%; 
    margin: 0 auto; 
    overfill: auto auto;  
    max-height: 696px; 
    background-color: white; 
    font-size: 25px; 
} 
</style> 
<script language="JavaScript"> 
</script> 
<div id = "div_id"> 
    <p>hello</p><br> 
    <p>hello</p><br> 
    <p>hello</p><br>  
</div> 
</body> 
</html> 
+0

'p'標記在頂部和底部都有默認的'margin'。而且在使用'display:block'元素時也不需要使用'br'。 –

回答

2

您的段落元素具有該邊距,而不是容器。所以這個規則應該解決它:

#div_id p {margin: 0;} 
+0

它減少了我猜。任何方式使它更小? – pandoragami

+1

它完全消失了。現在看到的休息是從'
'元素。如果您希望刪除空格並使用段落邊距/填充更精確地控制間距,請將其刪除。 – Shomz

+1

http://jsfiddle.net/7me9f/1/ – JunM