2012-06-06 31 views
1

爲什麼這個內聯CSS工作正常。爲什麼我的內聯CSS工作,但不是頭標籤中的CSS?

<a href="error.php" class="reportBug" 
style="display:scroll ;position:fixed; bottom:210px; right:2px;"> 
    <img src="images/Report_Error.png" border="0"> 
</a> 

但是,當我把CSS放入<head>時,它不起作用。

<head> 
    <style type="text/css"> 
    #reportBug { 
     display:scroll; 
     position:fixed; 
     bottom:210px 
     right:2px; 
    } 
    </style> 
</head> 

<body> 
    <a href="error.php" class="reportBug"> 
    <img src="images/Report_Error.png" border="0"> 
    </a> 
</body> 

這兩者之間的區別是什麼,爲什麼第二種方法沒有工作?

回答

5

將元素分配給使用.表示法的類時。 ID使用#

<style type="text/css"> 
#reportBug { 
    display:scroll; 
    position:fixed; 
    bottom:210px 
    right:2px; 
} 
</style> 

應該

<style type="text/css"> 
.reportBug { 
    display:scroll; 
    position:fixed; 
    bottom:210px 
    right:2px; 
} 
</style> 
1

您需要引用reportBug作爲這樣一個類:

.reportBug { 
display:scroll; 
position:fixed; 
bottom:210px 
right:2px; 
} 
1

在你的樣式表,你使用#reportBug。那是id="reportBug",而不是class="reportBug"

1

此外,我認爲你錯過了在課堂reportBugbottom需要;在最後的聲明的東西,否則,right: 2px;將被忽略。

.reportBug { 
    display:scroll; 
    position:fixed; 
    bottom:210px; 
    right:2px; 
} 
相關問題