Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a flexbox next to another flexbox?

I have two flex boxes with child elements. I wish each of these flex boxes to take up 50% of the page.

<div class="flexbox">
    ....
</div>
<div class="flexbox">
    ....
</div>

I have tried:

.flexbox{
    display:flex;
    width: 50%;
    ....

I have also thought about wrapping both divs in a container, and displaying flex on the container with a basis of 50%. I was just wondering if there was a way to do it without a container?

like image 682
panthro Avatar asked Mar 19 '26 02:03

panthro


1 Answers

To get this result you need to:

  1. Use display: inline-flex on .flexbox elements
  2. Remove white-space from HTML
  3. Use box-sizing: border-box for paddings and borders

* {
  box-sizing: border-box;
}
body,
html {
  padding: 0;
  margin: 0;
}
.flexbox {
  border: 1px solid black;
  display: inline-flex;
  width: 50%;
}
<div class="flexbox">
    ....
</div><div class="flexbox">
    ....
</div>
like image 169
Nenad Vracar Avatar answered Mar 22 '26 14:03

Nenad Vracar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!