CSS Grid Layout

In this example below you will see how to do a CSS Grid Layout with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by eranshapira, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright eranshapira ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>CSS Grid Layout</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="grid-container">
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
</div>

<style>
  * {
   --grid-row-size: 60px;
   --template-cells: var(--grid-row-size) var(--grid-row-size) var(--grid-row-size) var(--grid-row-size) var(--grid-row-size) var(--grid-row-size) var(--grid-row-size) var(--grid-row-size);
  }
</style>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/eranshapira/css-grid-layout-eMVVdp */
.grid-container {
  display: grid;
  height: calc(100vh - 20px);
  width: 100%;
  grid-template-columns: var(--template-cells);
  grid-template-rows: var(--template-cells);
  grid-auto-flow: row;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
}

.grid-container > div {
  color: white;
  background-color: gray;
  text-align: center;
  position: relative;
}

.grid-container > div:before {
  top: 50%;
  position: absolute;
  filter: blur(1.3px) opacity(50%);
  transform: translate(-50%, -50%);
  content: 'OMG';
}

.grid-item:nth-child(1) {
  grid-column: 8 span;  
}

.grid-item:nth-child(2) {
  grid-column: 2 span;
  grid-row: 5 span;
}

.grid-item:nth-child(3) {
  grid-column: 4 span;  
}
.grid-item:nth-child(4) {
  grid-column: 3 span;  
  grid-row: 4 span
}

Comments