Home > Web Front-end > CSS Tutorial > How to make a div cover an instance of another div in CSS

How to make a div cover an instance of another div in CSS

黄舟
Release: 2017-07-22 10:44:07
Original
4476 people have browsed it

There are two ways to cover one p on another p: one is to set margin to a negative value, and the other is to set absolute positioning.

You can set the z-index value based on personal circumstances

1->position is absolute

<html>
<head>
<style>
#p1{position:absolute;width:300px;height:300px;background:#ccc;}
#p2{position:absolute;left:0;top:0;width:200px;height:200px;background:red;filter:alpha(opacity=50);}
</style>
</head>
<body>
<pid="p1">这里是p1的内容
          <pid="p2"></p>
</p>
</body>
</html>
Copy after login


2->Use operation with negative margin

<html>
<head>
    <style>
   #p1 {position:relative; width:300px; height:300px;background:#ccc;}
    #p2 {position:relative; left:0; top:0;margin-top:-15px;width:200px; height:200px; background:red;filter:alpha(opacity=50);}
    </style>
</head>
<body>
<pid="p1"> 这里是p1的内容
          <pid="p2"></p>
</p>
</body>
</html>
Copy after login

The above is the detailed content of How to make a div cover an instance of another div in CSS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template