How to make a div appear below another div in CSS
P粉463418483
2023-08-30 11:28:21
<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>
Next time please share your code instead of screenshots, anyway, here is a sample code that does not use z-index
HTML
CSS
Basically, you create a 1x1 grid and overlap two divs on the same column and row.
https://codepen.io/ChrisCoder9000/pen/NWMJdBo