2010-05-06 115 views
0

我有一個關於圖像與CSS對齊的問題。例如,我創建瞭如下一個CSS類:html css圖像對齊

.link { 
background: url("images/image1.gif") scroll right; 
} 

及以下的標記

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     <title>Untitled Document</title> 
     <p class="link">This is a link</p> 
    </head> 
    <body> 
    </body> 
</html> 

當我在瀏覽器中,我得到的文本圖像,可檢查。我希望我的意思是

這是一個鏈接的文本後(這是我想要的形象出現)

+0

p標籤不屬於頭部,但我猜這只是一個錯誤;) - 基布布和靈魔有正確的答案。 – 2010-05-06 01:50:03

回答

2

嘗試

.link { 
    background: url("images/image1.gif") top right no-repeat; 
    padding-right: 32px; /* or the width of your image */ 
} 
+0

偉大的思想想象一樣:)哈哈,你打敗了我 – spirytus 2010-05-06 01:40:42

0

它不應該是位置不正確向右滾動? 你也可以給鏈接文本一些填充以清除背景圖片。

+0

「位置」在[背景屬性](http://www.htmldog.com/reference/cssproperties/background/)中無效。 – 2010-05-06 01:47:44

+0

它應該是背景位置或簡寫右上角。 – 2010-05-06 02:11:48

0

不知道我的理解對不對,但假設你想文本結束,你可以嘗試這樣的事情後立即顯示圖像:

.link { 
     background: url("images/image1.gif") scroll right; 
     padding-right: 20px; /* adjust to fit nicely with your design */ 
} 

希望它有助於:)