is position:static与position:relative相同,没有指定其他属性吗? [英] Is position: static identical to position: relative, with no other properties specified?
问题描述
是 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屋!