Home > Article > Web Front-end > How to make a div cover an instance of another div in CSS
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>
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>
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!