行内元素设置靠右对齐,在HTML中右对齐块元素

I'd like to right-align block elements in a floating container.

Assume the following markup.

...

...

current wanted

+-----------+ +-----------+

|+-------+ | | +-------+|

|| | | | | ||

|| | | | | ||

|+-------+ | ---> | +-------+|

|+----+ | | +----+|

|| | | | | ||

|+----+ | | +----+|

+-----------+ +-----------+

What I've tried:

div { text-align: right; } - works in IE8, fails in Firefox (naturally, the images are blocks and not supposed to be affected by text-align)

img { margin: 0 0 0 auto; } - works in Firefox, fails in IE8

floating the images to the right - does not work as I never want the images on the same line. Also, floated images no longer push down the following content.

What else can I try? I prefer a pure CSS solution, if that's at all possible.

UPDATE

Here's a fiddle that explains the full markup: http://jsfiddle.net/Tomalak/yCTHX/3/

Setting float: right; works for all real browsers, for IE8 it extends the image box in the row first over the entire width and pushes down the box with the text.

解决方案

div > img { float:right; clear:right; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值