您现在的位置: 365建站网 > 365文章 > css设置z-index 失效

css设置z-index 失效

文章来源:365jz.com 点击数:655 更新时间:2009-12-15 23:58

设置z-index时必须要固定位置,这样设置它的值时才能奏效(例如 position:absolute;)

下面是示例代码,在ff3.5.5和ie5.5~ie8.0RC1中通过,大家可以尝试着不固定其位置试试。

 

 <!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 runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
      

#king_of_diamonds {
    position: relative;
    background-color:gray;
    width:30px; height:30px;
    left: 145px;
    top: 145px;
}

#ace_of_diamonds {
    position:relative;
    background-color:blue;
    width:300px; height:300px;
    left: 160px;
    top: 130px;
    z-index: 1;
}

        
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="king_of_diamonds">
    a
    </div>
    <div id="ace_of_diamonds">
    b
    </div>
    </form>
</body>

生产内容,同时打通搜索引擎(SEO)与AI搜索引擎(GEO)流量入口的软件! 点击进入365建站器 »

您可能感兴趣的文章