is position:static与position:relative相同,没有指定其他属性吗? [英] Is position: static identical to position: relative, with no other properties specified?

查看:196
本文介绍了is position:static与position:relative相同,没有指定其他属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

position:static 等同于 position:relative ,没有顶部,底部,属性指定?



我虽然这是因为一个有 postion:absolute 的元素相对于第一个元素不具有 postion:static 。似乎任意使用 position:relative 创建一个元素,它的行为与 position相同:static 属性。图片我可能会缺少 static vs 相对


解决方案

答案是没有,两者都不同



position:static; 表示除了默认位置之外,不能使用 top,right,bottom,left 除非使用 position:relative,absolute或fixed ,您需要使用边距,此外, position:relative; / code>,当子元素位于 absolute 时,实际动作,所有元素都可以浮动在中position:relative; / code> div,如果你只是保持静态,他们会走出文档...



查看示例



Demo1 (保持div静态,使用顶部,左侧没有效果)



演示2 (使其 position:relative; 会影响顶部,左侧)



Demo3 (保持父div为静态,如果它位于绝对下,子流程就会流出)



演示4 (Child div位于 absolute 将测量从其父div定位的顶部,右侧,底部,左侧相对



1简洁,非常简单但功能强大 教程视频 清除您的疑问



还有一篇关于 CSS定位


Is position:static equivalent to position: relative with none of the top, bottom, right, or left properties specified?

I though of this because an element with postion: absolute be relative to the first element that does NOT have postion: static. It seems arbitrary to make an element with position: relative, which will behave identically to a position: static if no other properties are used. Figured I might be missing something about static vs relative.

Thanks!

解决方案

The answer is no, both are different

position: static; means nothing but default position, you cannot use top, right, bottom, left unless and until you use position: relative, absolute or fixed, you need to use margins, moreover, position: relative; comes in real action when the child elements are positioned absolute, so that all elements can float inside the position: relative; div, if you just keep it static, they will go out of the document...

Take a look at the examples

Demo1 (Keeping the div static and using top, left has no effect)

Demo2 (Making it position: relative; does effect top, left)

Demo3 (Keeping the parent div static, child will flow out if it's positioned absolute)

Demo4 (Child div positioned absolute will measure top, right, bottom, left from its parent div positioned relative)

This 1 is short and very simple but powerful tutorial video to clear out your doubts

And a short article on CSS positioning

这篇关于is position:static与position:relative相同,没有指定其他属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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