2010-12-07 70 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

它的工作通过将位置:绝对