Reputation: 4421
How do I put a transparent png image over a DIV without it affect anything else in the HTML document? I would do position absolute because it takes it out of the "normal flow of the document" but I have the whole website centered using "margin-left: auto;" and "margin-right: auto;"
Upvotes: 7
Views: 32071
Reputation: 1
You be able to use this css in a class_name in React js (in html is class="class_name") to show a div as a pop up (bring up) or send back.
<div classname="class_name">
...
</div>
.class_name{
position: absolute;
/**Put div hide*/
/**z-index: -9;*//
/**Put as pop up*/
/**z-index: 9;*//
}
Upvotes: 0
Reputation: 8267
Other solution is to use after like this:
.image:after{
content: "";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: url(https://i.imgur.com/DDdKwlk.png) no-repeat 0 0;
background-size: cover;
}
:)
Upvotes: 3
Reputation: 42818
Here's how it works. The example shows a transparent image absolutely positioned over another image, creating a mask.
Upvotes: 1
Reputation: 6638
if you apply position: relative
to the div
you want to cover then position: absolute
on the image will be calculated relative to the covered div rather than the whole page, if it is a child element. i.e.
<div id="tobecoverd">
<p>your content...</p>
<img src="./img/transparent.png" class="cover" />
</div>
div#tobecovered{
position: relative;
}
div#tobecovered img.cover{
position: absolute;
/* position in top left of #tobecovered */
top: 0; /* top of #tobecovered */
left: 0; /* left of #tobecovered */
}
Upvotes: 13
Reputation: 809
I think position:absolute
is more appropriate for normal usages as it follows the scroll.
Upvotes: 1