2015-10-06 59 views
-1

我有下面的代碼的圖像將作爲一個錨,這是框架代碼:爲什麼CSS設計器使用display:block?

<html> 
    <div id="outer"> 
    <div id="facebookButton"> 
    <a href="url"></a> 
    </div> 
    </div> 
</html> 

在CSS:

#facebookButton a{ 
    width:20px; 
    height:20px; 
    display:block; 
/*place code to load image*/ 
    } 

什麼display屬性設置的目的是這裏?有什麼好處?

+3

的可能的複製[是什麼顯示之間的差:inline和顯示:內聯塊(http://stackoverflow.com/questions/8969381/what-is-the-差顯示之間-內聯和 - 顯示內聯塊) – TylerH

回答

2

display屬性控制元素在頁面上的顯示方式。它有幾個值,但最常用的是:

  • 直列顯示元素作爲內聯(如<span>)。
  • 將元素顯示爲塊元素(如<div>)。
  • 隱藏元素。

在你的情況,<a>是一個內聯元素,所以它的文本中顯示的周圍:

<p>This is <a href="" style="border: 1px solid blue;">a link</a> within text.</p>

而是通過改變其display屬性block,這將是顯示爲一個div(與周圍文本分開的塊),您可以控制其高度和寬度:

<p>This is <a href="" style="display: block; border: 1px solid blue; width: 100px; height: 50px;">a link</a> within text.</p>

相關問題