2010-12-07 41 views
1

我在div中有一個文本,並且相鄰一個圖像。我希望圖像位於句尾,即right=0。但圖像總是放在句子的末尾。要放置的圖像需要右鍵:0px,但不需要

這是我的代碼。

<div id='xi' class='xc'>Text comes here and can be anything and any length<img src='images/QuestionExpandArrow.jpg' id='QuestionExpandArrow'></div> 

我想要圖像在句子的最右端。

感謝 讓

回答

1

你有沒有嘗試把圖像中的跨度與「浮動:權利;」風格(或與一個漂浮在右邊的類)?

<div id='xi' class='xc'>Text comes here and can be anything and any length<span style="float:right"><img alt="alt" src='images/QuestionExpandArrow.jpg' id='QuestionExpandArrow' /></span></div> 
+0

它轉到正確的,雖然,但它通過10px的 – X10nD 2010-12-07 14:28:04

+0

看起來好像正確遞減這可能是因爲在div風格設置的,或在身上,或通常在跨度或圖像上 - 如果您不使用任何其他樣式,它將起作用。所以你需要看看任何正在使用的樣式表的影響。 – amelvin 2010-12-07 14:34:55

2

應用float:right到圖像本身(通過單獨的樣式表,not inline style attribute)。您還需要有圖像come before the sentence in HTML

<head> 
    ... 
    <style type="text/css" media="all"> 
    #QuestionExpandArrow { float:right } 
    </style> 
</head><body> 
    ... 
    <div id='xi' class='xc'> 
    <img src='images/QuestionExpandArrow.jpg' id='QuestionExpandArrow'> 
    Text comes here and can be anything and any length 
    </div> 
    ... 
</body> 
1

這樣的文本之前把圖像,

<div id='xi' class='xc'><img src='images/QuestionExpandArrow.jpg' id='QuestionExpandArrow'/>Text comes here and can be anything and any length</div> 

然後在你的CSS添加#QuestionExpandArrow {浮動:權利; }它應該工作。

0

它的工作通過將位置:絕對