浮动右和位置绝对不能一起工作 [英] Float right and position absolute doesn't work together

查看:75
本文介绍了浮动右和位置绝对不能一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个div总是在其父div的右边,所以我使用 float:right



但是我也希望它在插入时不会影响其他内容,所以我使用 position:absolute



现在 float:right 不起作用,我的div总是位于父div的左边。



position:absolute;
right:0;



不需要 float:right 绝对定位



此外,请确保父元素设置为 position:relative;


I want a div to be always at the right of its parent div, so I use float:right. It works.

But I also want it to not affect other content when inserted, so I use position:absolute.

Now float:right doesn't work, my div is always at the left of its parent div. How can I move it to the right?

解决方案

Use

position:absolute; right: 0;

No need for float:right with absolute positioning

Also, make sure the parent element is set to position:relative;

这篇关于浮动右和位置绝对不能一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆