why div is under the image

Damon Qu

i want to put the div above the image, but i don't know why it is always under it event if i set the z-index attribute

my code likes:

<main id="content" role="main">
  <div style="text-align: center">
    <img src="assets/header-img.jpg" style="z-index: -1;">
  </div>

  <div class="container" style="background-color: bisque; height: 1000px; margin-top: -680px"></div>
</main>

there are two questions:

  1. I want to move up container-div, so i use "margin-top:-680px", 680px is the image height. is there any other optional solution?
  2. how can move the container-div above the image?
OK sure

Use relative positioning to be able to use z-index. Then you can use top as well which is a bit more robust than negative margins in my experience.

Default positioning is static which does not honour z-index.

<main id="content" role="main">
  <div style="text-align: center">
    <img src="assets/header-img.jpg" style="position: relative; z-index: 0;">
  </div>

  <div class="container" style="background-color: bisque; height: 1000px; position: relative; top: -680px; z-index: 1"></div>
</main>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

A image disappears under a div

Position image under div

i want my div to be under the image but it is overlapping, i cant find why

Why is there massive white space under my image in React? What's creating this mysterious div?

Why this Image and div is not aligned

Why is an image not showing in a div

targetting just one image under a div jQuery

CSS: Text under image div in empty space

Center text under a image/icon within a div

How to make an image go under a <div> in HTML?

How to put a button on the bottom of the div and under and image?

Why image always shows under buttons?

Why does the dropdownlist show under the div

why I see the background of the div under the canvas

how to scraping multiple image tag under div tag

Keep div from going under image with absolute positioning

bootstrap 3 nav navbar div jumps under logo image

Why does the div stretch correctly but not image?

Why is the image is not part of the div ? How to add it to DOM?

Why is '::after' pseudo-selector over the image and not under it?

Why are my links not u being centered under my image?

Why image is not displaying in Bootstrap written in phpstorm under laravel blade file?

Why two DIVs can not be draggable under parent DIV?

Why can't I change the label under my UpdateProgress div?

how can I grab an image from html, the image is not in img tag but under div class='blah blah'

Unable to get the div "tags" under the photo, it is auto placed next to the image within the div

Div goes under Div

Why does resizable() act differently for an image than it does for a div?

Why cant center an image inside a 'div' with 'float' right or left?