2013-04-03 29 views
0

我的項目包含下面的代碼,但我沒有得到#男,#d等。筆者相信新的CSS你的意思是在CSS #classname

 <div id="DivM" class="M" style="display: none;"> 
     </div> 
     <div id="DivB" class="B" style="display: none;"> 
     </div> 
     <div id="DivD" class="D" style="display: none;"> 
     </div> 
     <div id="DivL" class="L" style="display: none;"> 
     </div> 
     <div id="DivO" class="O" style="display: none;"> 
     </div> 

和CSS

#M {background: url(/images/M.png) no-repeat;width: 148px;height:90px;top: 18px;left:3px;outline:none;list-style:none;} 
#B {background: url(/images/B.png) no-repeat;width: 292px;height:90px;top: 0;left: 0;outline:none;list-style:none;} 
#D {background: url(/images/D.png) no-repeat;width: 158px;height:90px;top:18px;left:78px;outline:none;} 
#L {background: url(/images/L.png) no-repeat;width: 158px;height: 50px;top:82px;left:22px;outline:none;list-style:none;} 
#O {background: url(/images/O.png) no-repeat;width: 158px;height:90px;top:37px;left:36px;outline:none;list-style:none;} 
+1

包括hashtag「#」選擇元素的ID例如「#DivM」,而選擇你將使用的類。選擇器「.M」 –

+0

是不是可以擁有#classname.But當div被加載時(頁面被加載),圖像也會在頁面上看到。 –

+0

我明白了。這是我的錯誤。我應該使用.classname作爲class,#id作爲id。謝謝大家。 –

回答

1

您應該class和id http://www.w3schools.com/css/css_id_class.asp

手段之前,把一個#您嘗試添加樣式的ID讀了而不是一個類。 所以,如果你想用你的div類,你應該你的CSS更改爲:

.M {background: url(/images/M.png) no-repeat;width: 148px;height:90px;top: 18px;left:3px;outline:none;list-style:none;} 
.B {background: url(/images/B.png) no-repeat;width: 292px;height:90px;top: 0;left: 0;outline:none;list-style:none;} 
.D {background: url(/images/D.png) no-repeat;width: 158px;height:90px;top:18px;left:78px;outline:none;} 
.L {background: url(/images/L.png) no-repeat;width: 158px;height: 50px;top:82px;left:22px;outline:none;list-style:none;} 
.O {background: url(/images/O.png) no-repeat;width: 158px;height:90px;top:37px;left:36px;outline:none;list-style:none;} 
1

#用於選擇id屬性,而不是class屬性(即將爲.)。

0

該CSS不會有任何影響。在CSS #是一個ID選擇器,而.是一個類名選擇器。因此,例如:

<div id="mydiv"></div>#mydiv { }

凡爲<div class="mydiv"></div>.mydiv引用來引用。

0

#用於ID,你應該使用.上課:

.M {background: url(/images/M.png) no-repeat;width: 148px;height:90px;top: 18px;left:3px;outline:none;list-style:none;} 
.B {background: url(/images/B.png) no-repeat;width: 292px;height:90px;top: 0;left: 0;outline:none;list-style:none;} 
.D {background: url(/images/D.png) no-repeat;width: 158px;height:90px;top:18px;left:78px;outline:none;} 
.L {background: url(/images/L.png) no-repeat;width: 158px;height: 50px;top:82px;left:22px;outline:none;list-style:none;} 
.O {background: url(/images/O.png) no-repeat;width: 158px;height:90px;top:37px;left:36px;outline:none;list-style:none;} 
2

這些樣式將無法正常工作,與Mid#M目標元素,與Mclass.M目標元素。這會工作:

.M { ... } 
.B { ... } 
.D { ... } 
.L { ... } 
.O { ... } 

或者這樣:

#DivM { ... } 
#DivB { ... } 
#DivD { ... } 
#DivL { ... } 
#DivO { ... } 
相關問題