I want to create a page where my elements are displayed in a grid. I want to align items in rows. I want to visually obtain the following result , but I do not know how: https://codepen.io/shirkit/pen/KvZKOE/
And now I have this:
var back = ["red","blue","gray","black","green","cyan","brown","magenta"];
var i = 0;
$('#container .card').children().each(function() {
$(this).css('background-color',back[i++]);
if (i == back.length) i = 0;
});
#container {
display: flex;
flex-direction: row;
}
.card {
max-width: 200px;
width: 100%;
}
.card .image {
height: 150px;
}
.card .text {
height: 100px;
}
.card .list {
height: 50px;
}
#z1 .image {
height: 175px;
}
#z2 .text {
height: 120px;
}
#z3 .list {
height: 60px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<div id="z1" class="card">
<div class="image"></div>
<div class="text"></div>
<div class="list"></div>
</div>
<div id="z2" class="card">
<div class="image"></div>
<div class="text"></div>
<div class="list"></div>
</div>
<div id="z3" class="card">
<div class="image"></div>
<div class="text"></div>
<div class="list"></div>
</div>
</div>
Run codeHide resultClarification: heights in identifier selectors #z1 .image, #z2.text #z3 .listexist only to model the height that the components will have. Therefore, this is NOT an option to change these values. Also note that the height values of these elements / containers are not known in advance, so the margin parameter is also NOT an option.
, , , , , container , card .
, , .card, CSS display: grid #container. .image/.text/.list #container, , .
, .card .
: , , , , .