2015-06-20 149 views
-2

查看我的代碼以瞭解我的意思。我希望整個背景都是黑色的。但是,在有文字的地方,背景只有黑色。如何用純色填充背景的其餘部分

下面是圖片:example

<div style="background-color:black"> 
    <img src="http://csc2.madonna.edu/~brabahy/hw5/images/Mercury1.jpg" style="float:left; margin-right:10px" height="400" width="400"> 
    <p style="color:brown">Mercury is the smallest planet, and it's closest to the Sun of the eight planets in the Solar System. It has an orbital period of about 88 Earth days.</p> 
</div> 
+0

定義「整個」。據我所知,整個div的背景是黑色的。你的意思是整個頁面? – light

+1

會'body {background-color:black;}'嗎? – Banana

+0

您應該閱讀一些關於樣式以及如何使用它來控制元素邊距和填充的內容。 – arkascha

回答

1

當你試圖向其中發生的問題集

background-color: black; 

對於div是該div是採取文本的尺寸而不是圖像。背景顏色屬性設置正確,只是div的尺寸沒有設置。由於圖像高度爲400嘗試

style="background-color: black; height: 400px;" 

這將爲DIV工作,讓你的其他元素添加到身體整個身體也不會黑。

增加:

作爲每圖像添加着色body背景將不會產生所希望的輸出。

+0

這正是我所尋找的。謝謝! –

1

的index.html

<html> 

    <head> 
    <link rel="stylesheet" href="style.css"> 
    </head> 

    <body> 
    <img src="http://csc2.madonna.edu/~brabahy/hw5/images/Mercury1.jpg" style="float:left; margin-right:10px" height="400" width="400"> 
    <p style="color:brown">Mercury is the smallest planet, and it's closest to the Sun of the eight planets in the Solar System. It has an orbital period of about 88 Earth days.</p> 
    </body> 

</html> 

的style.css

body {background-color: black;} 
+0

這確實有效,實際上!我只是把它放在標籤中。