CSS3 grid without lines

In short, I want to have a flexible grid without using strings so that they are as dynamic as possible. The best approach I got is this:

an approach

* { box-sizing: border-box; }

.wrapper {
  font-size: 0;
  border: 1px solid blue;
}

.item {
  font-size: 16px;
  vertical-align: top;
  width: 25%;
  border: 2px dashed #F44336;
  display: inline-block;
  padding: 20px;
}

.item.c1-2 { width: 50%; }
.item.c2-3 { width: 66.66%; }
.item.c1-3 { width: 33.33%; }
<div class="wrapper">
  <div class="item">One Line.</div>
  <div class="item">Two<br>Lines.</div>
  <div class="item">Three<br>Lines<br>Here.</div>
  <div class="item">Four<br>Lines.<br><br>Yes, Really.</div>
  <div class="item c2-3">Big Line.</div>
  <div class="item c1-3">Small Line.</div>
  <div class="item c1-2">Equal Line.</div>
  <div class="item c1-2">Equal Line.</div>
</div>
Run codeHide result

What I missed here is that I cannot make the elements equal in height when they are on the same line so that they look like this:

wish

Now I am looking for a solution to make them equal in height without using strings for elements. Flexbox welcomed solutions, since I do not need to support older browsers; JS solutions are fine too.

+4
source share
2 answers

Like this?

I added these CSS options:

 display: flex;
 flex-wrap: wrap;

 display: inline-flex;

* { box-sizing: border-box; }

.wrapper {
  font-size: 0;
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
}

.item {
  font-size: 16px;
  vertical-align: top;
  width: 25%;
  border: 2px dashed #F44336;
  display: inline-flex;;
  padding: 20px;
}

.item.c1-2 { width: 50%; }
.item.c2-3 { width: 66.66%; }
.item.c1-3 { width: 33.33%; }
<div class="wrapper">
  <div class="item">One Line.</div>
  <div class="item">Two<br>Lines.</div>
  <div class="item">Three<br>Lines<br>Here.</div>
  <div class="item">Four<br>Lines.<br><br>Yes, Really.</div>
  <div class="item c2-3">Big Line.</div>
  <div class="item c1-3">Small Line.</div>
  <div class="item c1-2">Equal Line.</div>
  <div class="item c1-2">Equal Line.</div>
</div>
Run codeHide result
+2
source

Are you looking for something like this?

JSFIDDLE

-1

Source: https://habr.com/ru/post/1622231/


All Articles