2010-12-13 105 views
2

我有兩個同一類的標籤。這是我的這個類的css:IE7奇怪的背景位置行爲

.required 
{ 
    background-image:url(/img/required.png); 
    background-position: right; 
    background-repeat:no-repeat; 
    padding-right:10px; 
} 

在所有的瀏覽器中,兩個元素右上角有紅色的星星。但在IE 7中只有第一元素有這顆明星。我做錯了什麼?請幫幫我。

+0

我看不出任何錯誤的代碼。你能提供一個鏈接到一個工作的例子嗎? (也許在jsfiddle.com上,如果你不能告訴我們你的網站) – Spudley 2010-12-13 16:08:57

回答

1

@ Alexander.Plutov:使用required.pngborrowed進行演練,下面的代碼示例似乎做工精細(我剛剛凝聚的CSS規則的簡寫):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title></title> 

<style type="text/css"> 
.required 
{ 
    background: url(img/required.png) no-repeat right top; 
    padding-right: 15px; 
} 
</style> 
</head> 

<body> 

<form action="4430474.htm" method="post"> 
    <div> 
     <label for="field1" class="required">Field 1:</label> 
     <input type="text" name="field1" id="field1" size="40" /> 
    </div> 
    <div> 
     <label for="field2" class="required">Field 2:</label> 
     <input type="text" name="field2" id="field2" size="40" /> 
    </div> 
</form> 

</body> 
</html> 

你也許使用任何floatposition規則對於任何形式的東西?這些通常是IE6/7中的錯誤行爲。

+1

真的很感謝。你在表格中的位置說明是正確的。我的表單有UI對話框類。這個類有css規則'position:relative'。如果我刪除UI類一切OK。但是我需要這個類( – pltvs 2010-12-13 17:31:59

+0

@ Alexander.Plutov:如果你在'CSS'中註釋掉'/ * position:relative * /'那一行,你應該可以保持其他樣式不變。回答,因爲它也可能是一個'DOCTYPE'問題:http://stackoverflow.com/questions/2945660/jquery-ui-dialog-when-opened-ie7-browser-moves-instantly-to-the-bottom-of-所述-p/2976833#2976833 – stealthyninja 2010-12-13 17:44:52

1

不知道這是否會改變什麼,但你嘗試過

label .required 
{css here}