子div能不能相对于父div绝对定位啊?如何定位?求帮忙,急急急急急急急急急急急

[复制链接]
查看11 | 回复1 | 2011-5-6 09:31:39 | 显示全部楼层 |阅读模式
父div设置的是居中的,它的子div能不能根据父div的位置而定位,而不是根据body或者显示器边界定位;
就是说:能不能设置子div在父div里面距离父div左边100px,无论显示器分辨率怎么变子div一直在父div左边的100px处。
或者给出下图的css样式或者是完整的html代码,谢谢。谢谢
回复

使用道具 举报

千问 | 2011-5-6 09:31:39 | 显示全部楼层
divstyle=\"width:500px;height:500px;border:solid1px#900;\"
divstyle=\"width:100px;height:100px;background-color:#900;position:absolute;z-index:11;margin-top:10px;margin-left:10px;\"1/div
divstyle=\"width:100px;height:100px;background-color:#090;position:absolute;z-index:12;margin-top:120px;margin-left:10px;\"2/div
divstyle=\"width:100px;height:100px;background-color:#009;position:absolute;z-index:13;margin-top:10px;margin-left:120px;\"3/div
divstyle=\"width:100px;height:100px;background-color:#990;position:absolute;z-index:14;margin-top:120px;margin-left:120px;\"4/div
/div
要用margin-left,margin-right,margin-right,margin-bottom属性,而不是直接用top,left,right,bottom这些属性,前者是对父元素的,后者是对整个窗体的。还有z-index的值必须是不一样的,如果是一样的的话,那就表示它们在同一层面上,会相互拥挤。

仅供参考!呵呵
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行