div 固定位置

来源:百度知道 编辑:UC知道 时间:2024/06/15 17:53:11
我现在有个DIV 固定的大小,边距,但是 分辨率一变, 位置就变了,怎么可以让它自适应
#Layer1 {
position:absolute;
margin:0px auto;
left:238px;
top:395px;
width:654px;
height:210px;
z-index:3;
visibility: hidden;
background-color: #1E1E1E;
border-top-style: ridge;
border-right-style: ridge;
border-bottom-style: ridge;
border-left-style: ridge;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;

3楼的不行,4楼的也不好用!!

可以用绝对定位和相对定位的。<div style="position:absolute;"></div>这个是绝对定位。<div style="position:relative;"></div>这个是相对定位。

在最外面加一个div align=center的,限下大小,全屏,最底层,要看的:Layer1 在这个里面,margin-top:?px;margin-right:?px;

如果是左右居中就简单,就把需要居中的DIV设置一个margin:0 auto;的值,它就会在它的父标签的区域里自动居中,重要条件:它的width值必需是固定宽度或者固定百分比的值

position:absolute; 是固定定位,
应设置为position:relative;相对定位,就会自适应了

这里改下
margin-top:0px;margin-right:0px;
margin-left:0px margin-bottom 0px