<div>
I have several elements inside a <span>
, <button>
and <img>
aligned horizontally.
I need them to be centered vertically. They must be horizontally aligned and spaced between them occupying 100% of the <div>
.
When making the browser window smaller the first 3 elements should be vertically aligned and element 4 should remain horizontally aligned at 3
The code I have centers it vertically for me but I can't get the elements to be evenly spaced horizontally. I also don't know how to make the first 3 elements stand vertically in case the browser window gets smaller.
#container {
height: 100px;
width: 100%;
display: flex;
justify-content: center;
align-items; center;"
}
<div id="container">
<span class="t1">Elemento1</span>
<span class="t2">Elemento2</span>
<button class="b1">Elemento3</button>
<img class="i1">Elemento4</img>
</div>
You can do it with
justify-content: space-around;
to align it horizontally taking up all the space. And to vertically align elements at small resolutions, you can useflex-direction: column;
.Note
I recommend that you see how all the elements are used
flex
before you start with this, I leave you this link that is so you can easily understand how all the properties work.Try this:
For a better work with styles, it is better to use a framework, example bootstrap