Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CodeMyUI/0220220c702dc80a79262c49900148d8 to your computer and use it in GitHub Desktop.
Save CodeMyUI/0220220c702dc80a79262c49900148d8 to your computer and use it in GitHub Desktop.
Comic book style layout with CSS Grid

Comic book style layout with CSS Grid

Going crazy again with Grid CSS. This one is done in 30 minutes so the code quality isn't that good. I brute force my way to get the layout right quickly by using the dev tools as well. Anyway, only works well on browsers with Grid AND Clip Path. For Clip Path, it should work with Firefox 54 and above because I don't use SVG to generate it. Older browsers will get a boring layout instead.

A Pen by Aysha Anggraini on CodePen.

License.

<div class="wrapper">
<div class="news-item hero-item">
</div>
<div class="news-item standard-item">
</div>
<div class="news-item standard-item">
</div>
<div class="news-item standard-item">
</div>
</div>
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 1fr;
max-width: 1440px;
font-size: 0;
}
.hero-item,
.standard-item {
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
.news-item {
display: inline-block;
min-height: 400px;
width: 50%;
}
.hero-item {
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/divinity-ori-sin.jpg');
}
.standard-item:nth-child(2) {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/re7-chris-large.jpg");
}
.standard-item:nth-child(3) {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/bioshock-large.jpg");
}
.standard-item:nth-child(4) {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/53819/dishonored-large.jpg");
}
@supports (display: grid) {
.news-item {
width: auto;
min-height: 0;
}
.hero-item {
grid-column: 1 / span 2;
grid-row: 1 / 50;
-webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 75px), 0 100%);
clip-path: polygon(0 0, 100% 0, 100% calc(100% - 75px), 0 100%);
}
.standard-item:nth-child(2) {
grid-column: 1 / span 1;
grid-row: 50 / 100;
-webkit-clip-path: polygon(0 14%, 0 86%, 90% 81%, 100% 6%);
clip-path: polygon(0 14%, 0 86%, 90% 81%, 100% 6%);
margin-top: -73px;
}
.standard-item:nth-child(3) {
grid-column: 2 / span 1;
grid-row: 50 / 100;
-webkit-clip-path: polygon(13% 6%, 4% 84%, 100% 100%, 100% 0%);
clip-path: polygon(13% 6%, 4% 84%, 100% 100%, 100% 0%);
margin-top: -73px;
margin-left: -15%;
margin-bottom: 18px;
}
.standard-item:nth-child(4) {
grid-column: 1 / span 2;
grid-row: 100 / 150;
-webkit-clip-path: polygon(45% 0, 100% 15%, 100% 100%, 0 100%, 0 5%);
clip-path: polygon(45% 0, 100% 15%, 100% 100%, 0 100%, 0 5%);
margin-top: -107px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment