微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 CSS 与 Z 索引重叠元素

使用 CSS Z-Index 属性,开发人员可以将元素堆叠在一起。 Z-Index 可以有正值或负值。

注意 - 如果重叠的元素没有指定 z-index,则该元素将显示文档最后提到。

示例

让我们看一个 z-index 属性的示例 -

强> 现场演示

<!DOCTYPE html>
<html>
<head>
<style>
p {
   margin: 0;
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
}
div{
   margin: auto;
   position: absolute;
   top:0;
   left: 0;
   right: 0;
   bottom: 0;
}
div:first-child {
   background-color: orange;
   width: 270px;
   height: 120px;
   z-index: -2;
}
div:last-child {
   width: 250px;
   height: 100px;
   z-index: -1;
   background-color: turquoise;
}
</style>
</head>
<body>
<div></div>
<p>Fortran was originally developed by a team at IBM in 1957 for scientific calculations...................</p>
<div>
</div>
</body>
</html>

输出

以下是上述代码输出

使用 CSS 与 Z 索引重叠元素

示例

让我们看另一个z-index属性的示例:

实时演示

<!DOCTYPE html>
<html>
<head>
<style>
p {
   background: url("https://www.tutorialspoint.com/tensorflow/images/tensorflow-mini-logo.jpg");
   background-origin: content-Box;
   background-repeat: no-repeat;
   background-size: cover;
   Box-shadow: 0 0 3px black;
   padding: 20px;
   background-origin: border-Box;
}
</style>
</head>
<h2>Demo</h2>
<body>
<p>This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text. This is demo text. This is demo text. This is demo text.
This is demo text.</p>
</body>
</html>

输出

以下是上述代码输出 -

使用 CSS 与 Z 索引重叠元素

以上就是使用 CSS 与 Z 索引重叠元素的详细内容,更多请关注编程之家其它相关文章

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。