<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>两侧浮动广告效果</title>
</head>
<body>
<div id="floaterleft" style="z-index:100; left:1px; width:100px; position:absolute; top:50px; height:100px;">
<img src="left.jpg" /><br /><a οnclick="closeleft();"><img src="close.jpg" border="0" /></a>
</div>
<div id="floaterright" style="z-index:100; right:1px; width:100px; position:absolute; top:50px;">
<img src="right.jpg" /><a οnclick="closeleft();"><img src="close.jpg"; border="0" /></a>
</div>
<script language="javascript">
<!--
function closeleft(){
floaterleft.style.display="none";
floaterright.style.display="none";
}
-->
</script>
<center>两侧浮动广告</center>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>两侧浮动广告效果</title>
</head>
<body>
<div id="floaterleft" style="z-index:100; left:1px; width:100px; position:absolute; top:50px; height:100px;">
<img src="left.jpg" /><br /><a οnclick="closeleft();"><img src="close.jpg" border="0" /></a>
</div>
<div id="floaterright" style="z-index:100; right:1px; width:100px; position:absolute; top:50px;">
<img src="right.jpg" /><a οnclick="closeleft();"><img src="close.jpg"; border="0" /></a>
</div>
<script language="javascript">
<!--
function closeleft(){
floaterleft.style.display="none";
floaterright.style.display="none";
}
-->
</script>
<center>两侧浮动广告</center>
</body>
</html>
其中position可选值:
static(静态位置):默认。位置设置为 static 的元素,它始终会处于页面流给予的位置(static 元素会忽略任何 top、bottom、left 或 right 声明)。
relative(相对位置):位置被设置为 relative 的元素,可将其移至相对于其正常位置的地方,因此 "left:20" 会将元素移至元素正常位置左边 20 个像素的位置。
abosolute(绝对位置):位置设置为 absolute 的元素,可定位于相对于包含它的元素的指定坐标。此元素的位置可通过 "left"、"top"、"right" 以及 "bottom" 属性来规定。
fixed(固定位置):位置被设置为 fixed 的元素,可定位于相对于浏览器窗口的指定坐标。此元素的位置可通过 "left"、"top"、"right" 以及"bottom" 属性来规定。不论窗口滚动与否,元素都会留在那个位置。工作于 IE7(strict 模式)。
z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。
Z-index 仅能在定位元素上奏效(例如 position:absolute;)