How to put a transparent image over a div without affecting the page layout?

How to put a transparent png image through a DIV without affecting anything else in the HTML document? I would make the position absolute because it pulled it out of the "normal document flow", but I have the whole website using "margin-left: auto"; and "margin-right: auto;"

+5
source share
4 answers

if you apply position: relativeto divwhich you want to pay back, then position: absolutethe image will be calculated relative to the closed div, and not the whole page, if it is a child. 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 */
}
+12
source

, float - , , , - z-index.

css, , ,

0

, position:absolute , .

0

All Articles