2013-07-06 276 views
0

我是新來的HTML/CSS和做了一些教程,並試圖添加一個簡單的框。它顯示文本,但不顯示文本框。爲什麼我的盒子不顯示?

這是我的CSS

body 
{ 

background: #6a6a6a;  
background-image: -moz-linear-gradient(top, #6a6a6a 0%, #353535 100%); 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6a6a6a), color-stop(100%,#353535)); 
background-image: -webkit-linear-gradient(top, #6a6a6a 0%,#353535 100%); 
background-image: -o-linear-gradient(top, #6a6a6a 0%,#353535 100%); 
background-image: -ms-linear-gradient(top, #6a6a6a 0%,#353535 100%); 
background-image: linear-gradient(to bottom, #6a6a6a 0%,#353535 100%); 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#6a6a6a', endColorstr='#353535',GradientType=0); 

background-size: auto; 
background-position: center center; 
background-repeat: no-repeat; 
background-attachment: fixed; 





.box 
{ 
    background: #fff; 
    border: 6px solid #ccc; 
    height: 100px; 
    margin: 20px; 
    padding: 20px; 
    width: 400px; 
} 

} 

,這是我的HTML

<!DOCTYPE html> 

<html> 

<head> 
    <title>Where do you want to go?</title> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
    <link type="text/css" href="css/style.css" rel="stylesheet" /> 
</head> 

<body> 

<div class="box"> why doesn't this show up? </div> 

</body> 

</html> 

了「爲什麼不這樣顯示出來應該是在一個盒子裏,但事實並非如此。

+0

是CSS捲曲大括號錯位(沒有身後,兩個盒子)副本+粘貼到問題的錯誤? – WSkid

回答

0

如果你有id="box",.box如果你有class="box" 那麼,你剛纔編輯的問題,所以這是無效的

啊,發現問題。將.box {}移出機體{}。

+0

我改變了它,它仍然不起作用。 – user2555857

+0

剛編輯我的答案,看看它的結尾 – user2067005

+0

哦,我的上帝,它終於有效。非常感謝。 – user2555857

0
  1. 哪裏是你的CSS如果是不同的文件夾中更新href
  2. 試試這個百通

    body{ 
    } 
    .box{ 
    } 
    
0

CSS不嵌套。雖然這可能是你的直覺:

#id { 
    color: red; 

    .box { 
     border: 6px solid #ccc; 
    } 
} 

它是無效的。你必須做一些枯燥的工作:

#id { 
    color: red; 
} 

#id.box { 
    border: 6px solid #ccc; 
} 

這就是爲什麼我建議也查找SASS或LESS。