search

Home  >  Q&A  >  body text

How to make a div appear below another div in CSS

<p>I have two divs nested inside a div called .content. In it I have an img.png and I want another div with some boxes inside it which will be below the img.png</p> <pre class="brush:php;toolbar:false;"><div class="navBox"> <a href="#contact">/*Contact information*/</a> </div> <div class="navBox"> <a href="#expertise">/*Expertise*/</a> </div> <div class="navBox"> <a href="#projects">/*projects*/</a> </div></pre> <p>Also, I tried every possible combination of positioning, padding, margins, but not z-index (not sure how to use it) and didn't get good results. </p> <p>Thanks in advance. </p> <p>*Edit: I managed to use other distribution methods. </p> <pre class="brush:php;toolbar:false;">.mainBox{ position: relative; display: flex; width: 95%; height: 25vh; padding-top: 5vh; justify-content: space-evenly; align-items: left; vertical-align: middle; } .navBox{ padding-top: 25px; padding-left: 10px; padding-right: 10px; width: 20%; height: 20vh; text-align: center; top: 50%; background: transparent; } .navBox a:hover{ padding-top: 50%; background: transparent; color: var(--text-color); text-decoration: none; } a:visited, a:active, a:link{ text-decoration: none; color: var(--text-color); } .navBox a{ vertical-align: middle; color: var(--text-color); padding-top: 0.5rem; }</pre></p>
P粉463418483P粉463418483541 days ago637

reply all(1)I'll reply

  • P粉103739566

    P粉1037395662023-08-31 10:34:27

    Next time please share your code instead of screenshots, anyway, here is a sample code that does not use z-index

    HTML

    <div class="container">
      <div class="your-image">&nbsp;</div>
      <div class="your-boxes">&nbsp;</div>
    </div>

    CSS

    .container {
      display: grid;
      grid-template-rows: 1 / 1;
      grid-template-columns: 1 / 1;
      justify-items: center;
      align-items: center
    }
    
    .your-image {
      background-color: red;
      width: 250px;
      height: 250px;
      grid-area: 1 / 1 / 1 / 1;
    }
    
    .your-boxes {
      background-color: green;
      width: 150px;
      height: 150px;
      grid-area: 1 / 1 / 1 / 1;
      justify-self: center;
    }

    Basically, you create a 1x1 grid and overlap two divs on the same column and row.

    https://codepen.io/ChrisCoder9000/pen/NWMJdBo

    reply
    0
  • Cancelreply