我们在设计页面的时候会遇到,子DIV要控制在父DIV内部的固定位置,而且还有图层上下的关系。
解决方案:
父div的position使用relative,子div的position使用absolute,然后使用left和top进行定位。
需注意:
如果子div的position使用了fixed,就不能使用left了,则改成margin-left。
代码:
<div style="width:800px; height:1100px; background:#006699; margin:0 auto; position: relative;">
<div style="width:500px; height:50px; background:#ff6600; position: fixed; _position: absolute; top:2px; margin-left:50px; z-index:100;">Test!</div>
Hello World!
<div>