2013-03-07 28 views
1

我创建了一个新的div并放置了一些东西。然后我去了样式表并创建了相应的样式。当我刷新页面并检查元素时,div不会从样式表中拉出样式。帮助,因为它真的令人沮丧。div与类将不会识别CSS样式

下面是HTML

<div class="2columnlayout"> 
     <div id="managecontent1"> 
      <img src="img/wordpress-logo.png" /> 
      <p>Wordpress</p> 
     </div> 
     <div id="managecontent2"> 
      <img src="img/filezillaicon.png" /> 
      <p>F.T.P.</p> 
     </div> 
    </div> 

,这里是相应的CSS,它不会承认

.2columnlayout{ 
text-align: center; 
font-size: 24px; 
font-weight: 300; 
margin-top: 90px; 

}

回答

2

这样写:

.columnlayout2 

而不是

.2columnlayout 

因为CSS无法识别Class & ID与数字编号开始。

+0

或twocolumnlayout。 – Leeish 2013-03-07 04:45:08

+0

yup这也不错 – sandeep 2013-03-07 04:46:20

+0

感谢您的帮助 – zachstarnes 2013-03-07 04:46:44

0

类可能不以数字开头。将它重命名为twocolumnlayout

+0

感谢告诉我为什么。我不知道。觉得现在愚蠢哈哈:) – zachstarnes 2013-03-07 04:46:06

0

试试这个。

<div class="columnlayout"> 
     <div id="managecontent1"> 
      <img src="img/wordpress-logo.png" /> 
      <p>Wordpress</p> 
     </div> 
     <div id="managecontent2"> 
      <img src="img/filezillaicon.png" /> 
      <p>F.T.P.</p> 
     </div> 
    </div> 

样式表是:

.columnlayout div p{ 
text-align: center; 
font-size: 24px; 
font-weight: 300; 
margin-top: 90px; 
} 
0

CSS的syntax rules不允许以数字开头的标识符,诸如2columnlayout,所以在规则中的选择器是无效的,因此整个规则被忽略。

正如其他答案中的建议,您可以通过使用以字母开头的类名来避免此问题。适用时,这通常是最好的。

但是,一个类的名字可以以数字(限制在CSS语法,而不是在HTML语法)开始,如果你无法改变类的名称,你可以使用一个escape notation的数字。在这里,您可以通过\32 数字的(反斜杠,数位三,数字二,空间),(十六进制32)基于Unicode码数转义符号代替数字2

.\32 columnlayout { 
    /* declarations here */ 
}