JZK JZK - 1 year ago 64
HTML Question

background image and elements on it

I need to put some elements on picture:

image background

What is better approach ?

  • use img tag and align all elements on page with relative/absolute positioning ?

  • or use background-image css property ?

I've started with img tags but now I've decided for background-image. Sadly I'm suffering with basic problems, as when I'm using background property, image is only visible when there is something on it. I believe that is very simple problem, still.

Thank you for helping me out :)


header {
margin-top: 78px;
width: 100%;
background-position: center;
background-repeat: no-repeat;

Answer Source

If you want to overlay content on your background image (which it looks like you do) the best approach is to add a background image to your div and give it a height and then add content inside that div. For example:

<div class="bg-image">
   <div class="bg-image-module">
     <p>Some Content</p>

.bg-image {
   height: 500px; // change to be what you need.
   background-image: url(/path/to/image.jpg)";
   background-repeat: no-repeat;
   background-position: center;
   background-size: cover;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download