位置相对和正确的财产 [英] position relative and right property

查看:87
本文介绍了位置相对和正确的财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为,如果将div设置为相对,并且将其设为0,则将div一直定位到最右边(如果其父级为100%宽度).显然我错了,只有绝对的作品才是这样.因此,没有办法使其与亲戚一起工作吗?

I always thought by setting the div to relative and right 0 would position the div all the way to the right, if its parent was 100% width. Apparently I'm wrong and only absolute works like that. So is there no way to make it work with relative?

推荐答案

您必须将父级设置为相对父级,并将其父级设置为绝对定位.

You have to set the parent to be relative, and it's child to absolute positioning.

.parent{
  position: relative;
  width: 100%;
}
.right{
  position: absolute;
  width: 200px;
  height: 200px;
  background: red;
  top:0;
  right:0;
}

例如此处: http://jsfiddle.net/willemvb/n9Vrv/

这篇关于位置相对和正确的财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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