Reputation: 1596
This is my current html
<body>
<div class="header"></div>
<div class="side"></div>
<div class="stuff"></div>
<div class="footer"></div>
</body>
Is there anyway I could snap the sibling divs to the center, as if they were in a wrapper div? That way no matter what happened they would be side by side and in the center. I unfortunately having a hard time because I have other things in the parent div.
Is there any way I can do this using flexbox? and without adding html?
Upvotes: 1
Views: 238
Reputation: 372264
body {
display: flex;
flex-wrap: wrap;
justify-content: center; /* 1 */
align-content: space-between; /* 2 */
height: 100vh;
margin: 0;
}
div {
flex: 0 0 90%; /* 3 */
height: 100px;
border: 2px dashed red;
}
.side, .stuff {
flex-basis: 25%; /* 4 */
margin: 5px;
}
<div class="header">header</div>
<div class="side">stuff</div>
<div class="stuff">side</div>
<div class="footer">footer</div>
Notes:
Upvotes: 2