<main>
<section class="post-list" data-count="6"><ul></ul></section>
</main>
<aside>
<section class="post-list" data-count="4"><ul></ul></section>
</aside>
<template id="single-post">
<li>
<article class="post">
<img>
<div>
<h2></h2>
<p></p>
<button></button>
</div>
</article>
</li>
</template>
body {
display: grid;
grid-template-areas: "main aside";
grid-template-columns: 2fr 1fr;
gap: 40px;
height: 100%;
box-sizing: border-box;
padding: 20px;
margin: 0;
background: #1e1f22;
}
@media screen and (max-width: 767px) {
body {
grid-template-areas: "main" "aside" "footer";
grid-template-columns: 1fr;
}
}
main {
grid-area: main;
}
aside {
grid-area: aside;
}
.post-list {
container: post-list / inline-size;
}
.post-list > ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 10px;
padding: 0;
margin: 0;
list-style: none;
}
.post-list > ul > li {
container: post-list-item / inline-size;
padding: 10px;
border-radius: 5px;
background: #464646;
}
.post-list > ul > li > article {
display: grid;
grid-template-areas: "img text";
grid-template-columns: 100px 1fr;
gap: 5px;
}
.post-list > ul > li > article > img {
grid-area: img;
width: 100px;
height: 100px;
border-radius: 10px;
background-color: #e6f4f1;
}
.post-list > ul > li > article > div {
grid-area: text;
display: flex;
flex-direction: column;
gap: 5px;
}
.post-list > ul > li > article > div > h2 {
height: 20px;
border-radius: 5px;
margin: 0;
background: #21759b;
}
.post-list > ul > li > article > div > p {
height: 60px;
border-radius: 5px;
margin: 0;
background: #eee8a9;
}
.post-list > ul > li > article > div > button {
width: 80px;
height: 20px;
border: none;
border-radius: 5px;
background: #00beff;
}
@container post-list-item (max-width: 400px) {
.post-list > ul > li > article {
display: flex;
flex-direction: column;
}
.post-list > ul > li > article > img {
width: 100%;
}
}
@container post-list (max-width: 1500px) {
.post-list > ul {
grid-template-columns: 1fr 1fr 1fr;
}
}
@container post-list (max-width: 900px) {
.post-list > ul {
grid-template-columns: 1fr 1fr;
}
}
@container post-list (max-width: 600px) {
.post-list > ul {
grid-template-columns: 1fr;
}
}
/*
body {
display: grid;
grid-template-areas: "main aside";
grid-template-columns: 2fr 1fr;
gap: 40px;
height: 100%;
box-sizing: border-box;
padding: 20px;
margin: 0;
background: #1e1f22;
@media screen and (max-width: 767px) {
grid-template-areas: "main" "aside" "footer";
grid-template-columns: 1fr;
}
}
main {
grid-area: main;
}
aside {
grid-area: aside;
}
.post-list {
container: post-list / inline-size;
> ul {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 10px;
padding: 0;
margin: 0;
list-style: none;
@container post-list (max-width: 1500px) {
grid-template-columns: 1fr 1fr 1fr;
}
@container post-list (max-width: 900px) {
grid-template-columns: 1fr 1fr;
}
@container post-list (max-width: 600px) {
grid-template-columns: 1fr;
}
> li {
container: post-list-item / inline-size;
padding: 10px;
border-radius: 5px;
background: #464646;
> article {
display: grid;
grid-template-areas: "img text";
grid-template-columns: 100px 1fr;
gap: 5px;
@container post-list-item (max-width: 400px) {
display: flex;
flex-direction: column;
}
> img {
grid-area: img;
width: 100px;
height: 100px;
border-radius: 10px;
background-color: #e6f4f1;
@container post-list-item (max-width: 400px) {
width: 100%;
}
}
> div {
grid-area: text;
display: flex;
flex-direction: column;
gap: 5px;
> h2 {
height: 20px;
border-radius: 5px;
margin: 0;
background: #21759b;
}
> p {
height: 60px;
border-radius: 5px;
margin: 0;
background: #eee8a9;
}
> button {
width: 80px;
height: 20px;
border: none;
border-radius: 5px;
background: #00beff;
}
}
}
}
}
}
jQuery( document ).ready( function() {
let singlePost = jQuery( 'template#single-post' ).html();
jQuery( '.post-list' ).each( function() {
for ( let i = 0; i < jQuery( this ).data( 'count' ); i++ ) {
jQuery( this ).children( 'ul' ).append( singlePost );
}
} );
} );
This Pen doesn't use any external CSS resources.