javascript的网页两侧浮动广告

<!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>

其中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;)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值