我有一个div要绝对定位在左上方,请问下面两种写法区别在哪里?
div{
position: absolute;
left:0;
top:0;
}
div{
position: absolute;
left:0;
top:0;
right:0;
bottom:0;
}
我有一个div要绝对定位在左上方,请问下面两种写法区别在哪里?
div{
position: absolute;
left:0;
top:0;
}
div{
position: absolute;
left:0;
top:0;
right:0;
bottom:0;
}
mozilla的文档这样写
When both top and bottom are specified, as long as height is
unspecified, auto, or 100%, both top and bottom distances will be
respected. Otherwise, if height is constrained in any way, the top
property takes precedence and the bottom property is ignored.
也就是,你的后一种写法可能导致div的大小拉大为全屏,如果div大小已经被限制住,right和bottom会被忽略。
3 回答4.8k 阅读✓ 已解决
5 回答2k 阅读
2 回答1.9k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.5k 阅读
4 回答2.2k 阅读
2 回答999 阅读✓ 已解决
第一种写法只是定位。
第二种写法会撑满距离自己最近的有定位属性的父级节点。