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;"
The opacity of background for transparency can be made by using the rgba colors of CSS. If you want to make the background of div transparent, you may use CSS opacity property. However, the opacity property may affect the inner element of the div also and make them transparent too.
This is some text that is placed in the transparent box. First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.
This is the transparency div element overlap over an image. The above example contains the image over which the div element overlapped. The overlapped div element contains a background with transparency using the RGBA color of CSS.
The opacity property specifies the opacity/transparency of an element. The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent: The opacity property is often used together with the :hover selector to change the opacity on mouse-over: The first CSS block is similar to the code in Example 1.
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 */
}
Here's how it works. The example shows a transparent image absolutely positioned over another image, creating a mask.
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;
}
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With