网络编程
位置:首页>> 网络编程>> 网页设计>> 两侧背景自动延伸的CSS实现方法

两侧背景自动延伸的CSS实现方法

作者:摄氏度 来源:Prower 发布时间:2010-02-24 09:42:00 

标签:position,absolute,css,背景

方法来源于土豆网的导航,在这里纪录一下实现的思路。

主要是利用 position 属性的 absolute relative 配合 z-index 来实现的,通过position:absolute将需要平铺的背景层叠在另一背景上,这样即可以实现同一位置的两个背景,再使用z-index将内容提升到最高阶显示。

<div id=”a”>
<div id=”b”>
<ul>
<li><a href=”https://www.aspxhome.com/asp/”>asp教程</a></li>
<li><a href=”https://www.aspxhome.com/javascript/”>javascript教程</a></li>
<li><a href=”https://www.aspxhome.com/photo/”>平面设计</a></li>
</ul>
<div id=”c”></div>
</div>
<div id=”d”></div>
</div>

首先将其中一个背景样式写在<div id=”a”>上,然后是将另一个背景样式写在<div id=”d”>上,<div id=”b”>为内容层,<div id=”c”>是另一个背景样式层,可以自由的出现在<div id=”b”>里面的任何一个位置。如土豆网中间的那个有弧线的背景。

然后是样式方面:

#a {background:#f00; height:50px; position:relative; width:100%;}
#b {height:50px; margin:0 auto; position:relative; width:950px; z-index:9000;}
#c {background:#ff0; height:50px; position:absolute; left:100px; top:0; width:100px; z-index:-1;}
#d {background:#f60; height:50px; position:absolute; left:0; top:0; width:50%; z-index:1;}
ul {line-height:50px; position:relative; z-index:9001;}

 

演示:


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com