I the following HTML and CSS (the .type-a
part), it is using the CSS Grid.
(you can see the CodePen clicking here)
What I need is to make all elements with .col1
class to be correctly aligned on the first column - while at the same time making .col2
span the entire rows.
Changing the HTML is not an option (I know it's easy to fix this by changing the HTML).
We will never know exactly how many rows .col1
will have and I do want to avoid creating 1000 rows to make it work (like you can see on .type-b
).
.container {
display: grid;
grid-auto-columns: 50%;
grid-auto-flow: dense;
/* Decorative */
color: #ffffff;
text-align: center;
}
.col1 {
grid-column: 1;
}
.col2 {
grid-column: 2;
}
// Type B
.type-b>.col2 {
grid-row: 1 / 100;
}
// Decorative Styles
.divider {
height: 1px;
background: #B0BEC5;
margin: 30px;
}
.content-a {
background: #5C6BC0;
}
.content-b {
background: #7E57C2;
}
.content-c {
background: #AB47BC;
}
.content-d {
background: #FFA726;
}
<h3>Type A</h3>
<div class="container type-a">
<div class="col1 content-a">Content A</div>
<div class="col1 content-b">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac auctor erat. Phasellus porta nec dolor ut egestas. Praesent pretium elit vel risus iaculis, vel condimentum lorem volutpat. Nunc placerat massa ac venenatis dictum. Donec ullamcorper, magna
efficitur laoreet euismod, arcu neque aliquam purus, sed ornare dolor sem sed est.
</div>
<div class="col1 content-c">Content C</div>
<div class="col2 content-d">
<img src="https://picsum.photos/200/300">
</div>
</div>
<div class="divider"></div>
<h3>Type B (What I want)</h3>
<div class="container type-b">
<div class="col1 content-a">Content A</div>
<div class="col1 content-b">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac auctor erat. Phasellus porta nec dolor ut egestas. Praesent pretium elit vel risus iaculis, vel condimentum lorem volutpat. Nunc placerat massa ac venenatis dictum. Donec ullamcorper, magna
efficitur laoreet euismod, arcu neque aliquam purus, sed ornare dolor sem sed est.
</div>
<div class="col1 content-c">Content C</div>
<div class="col2 content-d">
<img src="https://picsum.photos/200/300">
</div>
</div>