一个关于层的位置的问题

nc2015 2004-12-31 10:23:41

怎么才能使层始终在IE里居中,从而与背后的居中网页框架一至?否则IE还原或最大化时,此层会移位。望大侠指点。

===========================================================================
<html>
<head>

<style type="text/css">
<!--
table{font-size:9pt;color=#999999}
A:link { color:#e80000;text-decoration:none }
A:active { color:#e80000;text-decoration:none }
A:visited { color:#e80000;text-decoration:none }
A:hover { color:#e80000; text-decoration:underline }
.style1 {color: #FFFFFF}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
</script>
</head>
<body leftmargin="0" rightmargin="0" background="img/bac_point.jpg">
<div id="Layer1" style="position:absolute; width:750px; height:20px; z-index:0; background-color: #666666; layer-background-color: #666666; border: 1px none #000000; visibility: visible; top: 170px; left: 127px;">
<table width="750" height="20" border="0" align="center">
<tr>
<td width="61" height="20" onMouseOver="MM_showHideLayers('menu1','','show')" onMouseOut="MM_showHideLayers('menu1','','hide')"><span class="style1">首页</span></td>
<td width="61" height="20" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="MM_showHideLayers('Layer2','','hide')"><span class="style1">A123</span></td>
<td width="71" height="20"><span class="style1">A124</span></td>
<td width="61" height="20"><span class="style1">A125</span></td>
<td width="61" height="20"><span class="style1">A126</span></td>
<td width="61" height="20"><span class="style1">A127</span></td>
<td width="61" height="20"><span class="style1">A128</span></td>
<td width="233" height="20"> </td>
</tr>
</table>
</div>
<div id="menu1" style="position:absolute; left:147px; top:193px; width:140px; height:123px; z-index:2; background-color: #666666; layer-background-color: #666666; border: 1px none #000000; visibility: hidden;" onMouseOut="MM_showHideLayers('menu1','','hide')" onMouseOver="MM_showHideLayers('menu1','','show')">
<table width="128" border="0">
<tr>
<td width="118" onMouseOver="MM_showHideLayers('menu1','','show')" onMouseOut="MM_showHideLayers('menu1','','hide')"><span class="style1"><a href="http://www.china.com">China</a></span></td>
</tr>
<tr>
<td><span class="style1">Japan</span></td>
</tr>
<tr>
<td><span class="style1">Amerian</span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</div>
<div id="Layer2" style="position:absolute; left:300px; top:193px; width:148px; height:115px; z-index:3; background-color: #999999; layer-background-color: #999999; border: 1px none #000000; visibility: hidden;" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="MM_showHideLayers('Layer2','','hide')">
<table width="141" border="0">
<tr>
<td><span class="style1">;ljdsfgklsdfjg;l</span></td>
</tr>
<tr>
<td><span class="style1">dfsgsdfgsdf</span></td>
</tr>
<tr>
<td><span class="style1">sdfgsdfg</span></td>
</tr>
<tr>
<td><span class="style1">sdfgsdfgsdf</span></td>
</tr>
<tr>
<td><span class="style1">sdfgsdfgsdfg</span></td>
</tr>
</table>
</div>
<center>
<table width="750" height="50" cellpadding="0" cellspacing="0" bgcolor="#666666"><td></td></table>
</center>
</body>
</html>
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lienzhu 2004-12-31
  • 打赏
  • 举报
回复
给table一个id,以他为参照点

<table id="tb" width="750" height="50" cellpadding="0" cellspacing="0" bgcolor="#666666"><td></td></table>
</center>
<script language="javascript">
<!--
window.onresize = resizeDiv;
function resizeDiv()
{
Layer1.style.left=tb.offsetLeft;
}
resizeDiv()
-->
</script>
孟子E章 2004-12-31
  • 打赏
  • 举报
回复
<html>
<head>
<script>
function Is() {
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) &&
((agent.indexOf('spoofer') == -1) &&
(agent.indexOf('compatible') == -1)));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.0") == -1));
this.ie5 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.0") != -1));
this.ie55 = (this.ie && (this.major == 4) &&
(agent.indexOf("msie 5.5") != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
}

var is = new Is();

function layerObject(id,position,left,top,visibility) {
if (is.ie5|| is.ie55||is.ie6|| is.ns6){
this.obj = document.getElementById(id).style;
this.obj.position = position;
this.obj.left = left;
this.obj.top = top;
this.obj.visibility = visibility;
return this.obj;
}
}
function layerSetup() {
centerLyr = new layerObject(id,'absolute',
(page_width-parseInt(document.getElementById(id).style.width))/2,
(page_height-parseInt(document.getElementById(id).style.height))/2,
'visible');
}
</script>
<style type="text/css">
<!--
.main {
font-family: 宋体;
font-size: 16px;
color: #FBEED5;
background-color:red;
text-decoration: none
}
-->
</style>
</head>
<body bgcolor="#999999" onLoad="
id='centerLayer'
if(is.ns6) {
page_width=innerWidth;
page_height=innerHeight;
layerSetup();
} else if(is.ie5 || is.ie55 ||is.ie6) {
page_width=document.body.clientWidth;
page_height=document.body.clientHeight;
layerSetup();
}"
onResize=" history.go(0); ">
<div id="centerLayer"
style="position: absolute; width:200px; height:24px;
left: 0px; top: 0px; z-index: 6; visibility: hidden;">
<span class="main">居中层的例子居中层的例子居中层的例子居中层的例子居中层的例子</span>
</div>
</body>
</html>

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧