The following example I want column to be equal width and spacing.
But I don’t want to use width, min-width, max-width
property for any columns.
Anyone help me to achieve this by using flex or any other method.
.d-flex {
display: flex;
}
.d-flex .col {
margin: 5px;
background: #7adaff;
}
<div class="d-flex">
<div class="col">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
</div>
<div class="col">
Lorem Ipsum is simply dummy tex
</div>
<div class="col">
Lorem Ipsum
</div>
<div class="col">
Lorem Ipsum
</div>
<div class="col">
Lorem Ipsum is simply dummy text of the printing and typesetting industryLorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries,
</div>
</div>
If you have any questions kindly drop your comment.
2
Answers
There are a couple of possibilities, one of which uses CSS flex-box layout, and the other using CSS Grid; neither using an explicit
width
,min-width
, ormax-width
but the flex solution does useflex-basis
, but this feels like exploiting a loophole or technicality:More sensibly, we can use CSS Grid, and exploit the
fr
fractional units:Following OP’s comment (below):
My only suggestion is to use JavaScript, though how that JavaScript should work depends on the precise circumstances and – potentially – exceeds the scope of the original question. However, the following is certainly possible:
JS Fiddle demo.
References:
calc()
.display
.flex-basis
.gap
.grid-template-columns
.repeat()
.Bibliography:
In this instance I would prefer to set the
flex
shorthand value per child of the flexbox parent container. Combined with a custom attribute ([col]
) instead of a class (.col
) it will become very easy to vary between column widths if so required (comparable to using grid fractions).Further explanations can be found in the CSS of the snippet