Background image in div is pushing the content that i want it to be BEHIND, is pushing it down. How do i fix this? I want to add a black overlay and change the opacity for this, normally i’d just do it in css for that class.
Can you help me put this image behind the intro or basically behind everything you see in the code pen? I just want it to be for that div.
Using the IMG tag creates an “element” or block of content, which in this case is pushing your other content down.
The easy way to use the image as a background is to target the selector (in this case your class “nav_bar”) and assign it a background property. There are other ways to move text over and image using relative and absolute positioning but that’s more complicated.
I’m still learning HTML/CSS myself but I will help the best I can, if anybody see’s any mistakes in my answer please feel free to correct me.
Yes, but it’s not as straight forward as it probably should be. My first thought was to add the opacity property to the same selector as the background property which will work, unfortunately it will also add opacity to everything else in that element.
There are a few workarounds though that you can use and I created this pen so that you can try them out.
The first workaround is to add a linear gradient on top of the background image. You can adjust the color of the overlay to tint the image or use black to darken the image and make text more readable.
The second workaround is to add an additional element just for the background and use absolute positioning to place it on top of your main element. Because the background is the only object in the new div it can be targeted with opacity without affecting the opacity of other objects.
The last workaround is to use a pseudo element and absolute positioning similar to the linear gradient overlay.