css设置模态框如何显示在最上层

时间:2026-02-13 06:16:35

1、初始代码如下:

<html>

<head>

<title></title>

</head>

<style type="text/css">

.red{

     width:100px;

     height: 100px;

    background: red;

     position: absolute;

}

.yellow{

     width: 200px;

     height: 100px;

    background: yellow;

    position: absolute;

}

</style>

<body>

     <div class="red"></div>

     <div class="yellow"></div>

</body>

</html>

可以看出橙色的div明显在红色的div上面,现在使用z-index属性控制红色div在橙色div上面。

css设置模态框如何显示在最上层

2、代码如下:

<html>

<head>

<title></title>

</head>

<style type="text/css">

.red{

      width:100px;

     height: 100px;

     background: red;

    position: absolute;

     z-index: 11;

}

.yellow{

      width: 200px;

     height: 100px;

     background: yellow;

     position: absolute;

}

</style>

<body>

        <div class="red"></div>

        <div class="yellow"></div>

</body>

</html>

效果如下图:

css设置模态框如何显示在最上层

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com