Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of display property of flex box items

Tags:

css

flexbox

Is there any benefit or reason to change display property of a flex box item?

Especially, I'm interested in using display:block and display:inline-block

like image 394
Roman Roman Avatar asked Oct 27 '25 08:10

Roman Roman


1 Answers

From the specifciation:

The display value of a flex item is blockified: if the specified display of an in-flow child of an element generating a flex container is an inline-level value, it computes to its block-level equivalent. (See CSS2.1§9.7 [CSS21] and CSS Display [CSS3-DISPLAY] for details on this type of display value conversion.)

So basically, setting inline-block or block will do nothing as both will get computed to block but you can set table or inline-table and your flex item will behave as a table. Same thing if you set inline-grid or grid

.box {
  display: flex;
  margin:5px;
}

.box>div {
  height: 50px;
  width: 100%;
  background: red;
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 1fr;
  grid-gap: 20px;
}

span {
  border: 2px solid green;
}
<div class="box">
  <div>
    <span></span>

    <span></span>
  </div>
</div>

<div class="box">
  <div style="display:inline-grid;">
    <span></span>

    <span></span>
  </div>
</div>

For the second case you can see it computes to grid

enter image description here

like image 100
Temani Afif Avatar answered Oct 28 '25 23:10

Temani Afif



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!