What is the simplest way to place div above the image in the div container using flex box?
The expected result is shown in the image example.
That is the starter code:
<div className={"main"}> Корзина <div> <div className={"num"}>1</div> <image/> </div> </div>
3
Put the container position: relative and the image position: absolute and then use flexbox for alignment.
position: relative
position: absolute
.parent-container{ display: flex; align-items: center; } .container{ position: relative; display: flex; justify-content: center; align-items: center; margin-left: 30px; } .container img{ position: absolute; z-index: -1; }
<div class="parent-container"> Корзина <div class="container"> <div>1</div> <img src="https://picsum.photos/seed/picsum/50/50" alt=""> </div> </div>
Can you please elaborate it which div exactly you need under the image and there are many div element in this example
I got it what you want
div.main { display:flex; align-items: center; color:white; background-color: black; width: 120px; justify-content: center; } .container{ position: relative; display: flex; align-items: center; justify-content: center; } div.number{ position: absolute; } <div class="main"> Корзина <div class="container"> <div class="number">1</div> <img src="https://img.icons8.com/?size=512&id=Zyo5wDjgJxRW&format=png" alt="image" height="40" width="40"/> </div> </div>
We can provide background on the upper div and place other content inside the inner div. The position properly handles those things here, so we can have inner div content on top of the upper div.
#background{ display: flex; background-image: url("https://e1.pxfuel.com/desktop-wallpaper/908/281/desktop-wallpaper-non-copyrighted-no-copyright.jpg"); position:relative; } #content{ font-size:40px; color:red; padding:20px; margin:100px auto 100px auto; }
<!DOCTYPE html> <html> <head> </head> <body> <div id="background"> <div id="content"> Your content goes here </div> </div> </body> </html>
Click here to cancel reply.
3
Answers
Put the container
position: relative
and the imageposition: absolute
and then use flexbox for alignment.Can you please elaborate it which div exactly you need under the image and there are many div element in this example
I got it what you want
We can provide background on the upper div and place other content inside the inner div. The position properly handles those things here, so we can have inner div content on top of the upper div.