JSFiddle - React, Tailwind, and code Playground

by Kirubel Girma

HTML

<div class="cont">
  <div class="cont_page">
    <div class="item1">Header</div>
    <div class="item2">Menu</div>
    <div class="item3">Main</div>
    <div class="item4">Right</div>
    <div class="item5">Footer</div>
  </div>
</div>

CSS

* {
  margin: 0em;
}

body {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #525659;
}

.item1 {
  grid-area: header;
}

.item2 {
  grid-area: menu;
}

.item3 {
  grid-area: main;
}

.item4 {
  grid-area: right;
}

.item5 {
  grid-area: footer;
}

.cont {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: scroll;
}

.cont_page>div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

.cont_page {
  position: relative;
  display: table;
  margin: 3em auto;
  max-width: 640px;
  min-width: 300px;
  width: 66vw;
  height: 1200px;
  grid-template-areas: 'header menu' 'menu main' 'menu footer';
  grid-gap: 10px;
  background: #2196F3;
  padding: 10px;
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    height: 297mm;
  }
  
  *{-webkit-print-color-adjust: exact;}
  
  .cont {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: scroll;
  }
  .cont_page>div {
    background-color: rgba(255, 255, 255, 0.8);
    text-align: center;
    padding: 20px 0;
    font-size: 30px;
  }
  .cont_page {
    position: relative;
    display: table;
    margin: 3em auto;
    max-width: 640px;
    min-width: 300px;
    width: 66vw;
    height: 1200px;
    grid-template-areas: initial;
    grid-gap: initial;
    background: initial;
    padding: initial;
  }
}

JavaScript

window.print()