Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<main class="wrapper">
  <menu class="menu">
    <h1>GRID</h1>
    <section class="info">
      <p class="screenInfo">a</p>
      <p class="gridInfo">a</p>
    </section>
    <section class="controls">
       <button aria-pressed="false" type="button" class="navToggle">collapse nav</button>
      <button aria-pressed="false" type="button" class="sidebarToggle">show sidebar</button>
    </section>
    
  </menu>
  <nav aria-expanded="true" class="nav"><p>navigation</p>
  </nav>
  <aside aria-hidden="false" class="sidebar"><p>sidebar</p>
    <div class="handle"></div>
  </aside>
  <section class="grid">
    <div><p>1</p></div>
    <div><p>2</p></div>
    <div><p>3</p></div>
    <div><p>4</p></div>
    <div><p>5</p></div>
    <div><p>6</p></div>
    <div><p>7</p></div>
    <div><p>8</p></div>
    <div><p>9</p></div>
    <div><p>10</p></div>
    <div><p>11</p></div>
    <div><p>12</p></div>
  </section>
</main>
              
            
!

CSS

              
                :root {
  --navSize: 304px;
  --sidebarSize: 64px;
  --gutterSize: 16px;
  --colNumber: 4;
  --colWidth: 1;
  --marginSize: 0 16px;
  
  --colorBackground: #EBECF0;
  --colorPanel: #FFFFFF;
  --colorColumn: transparent;
  --colorColumnBorder: #C1C7D0;
  --colorPrimaryText: #172B4D;
  --colorSecondaryText: #6B778C;
  --colorColText: #0052CC;
  --colorDivider: #DFE1E6;
  --colorPrimaryInteraction: #0052CC;
  --colorSecondaryInteraction: #4C9AFF;
  --colorButtonHover: #EBECF0;
  --colorButtonSelected: #42526E;
  --colorButtonSelectedText: #FFFFFF;
  --colorSidebar: #FFFFFF;
  --colorNav: #FFFFFF;
  --colorGrid: transparent;
}

html {
  box-sizing: border-box;
}

 body {
  font-family: 'Roboto Mono', monospace;
  font-size: 12px;
  text-align: center;
  background: var(--colorBackground);
  color: var(--colorPrimaryText);
}

*,
*:before,
*:after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
  outline: none;
}

/* Styling */
.menu{
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: 1fr;
  justify-items: start;
  border-bottom: 1px solid var(--colorDivider);
  background: var(--colorPanel);
}

h1{
  align-self: center;
  justify-self: start;
  margin-left: 24px;
  font-size: 40px;
}

.info{
  display: grid;
  margin-left: 32px;
  justify-items: start;
  align-content: space-evenly;
  color: var(--colorSecondaryText);
}

.controls{
  display: grid;
  justify-items: end;
  align-content: space-evenly;
  margin-right: 24px;
}

.navToggle, .sidebarToggle{
  transition: all 0.25s ease;
  font-size: 12px;
  font-family: 'Roboto Mono', monospace;
  color: var(--colorSecondaryText);
  background: transparent;
  border-radius: 16px;
  border: 1px solid var(--colorDivider);
  height: 32px;
  width: 160px;
  align-self: center;
}

.navToggle[aria-pressed="false"]:hover, .sidebarToggle[aria-pressed="false"]:hover{
    background: var(--colorButtonHover);
  cursor: pointer;
  }

.navToggle[aria-pressed="true"]:hover, .sidebarToggle[aria-pressed="true"]:hover{
    cursor: pointer;
}
  
   .navToggle[aria-pressed="false"] {
    background: transparent;
  }

  .navToggle[aria-pressed="true"] {
    background: var(--colorButtonSelected);
    color: var(--colorButtonSelectedText);
  } 
  
  .sidebarToggle[aria-pressed="true"] {
    background: var(--colorButtonSelected);
    color: var(--colorButtonSelectedText);
  }

   .sidebarToggle[aria-pressed="false"] {
    background: transparent;
  } 

.nav{
/*   display: none; */
  display: grid;
  position: relative;
  justify-content: center;
  border-radius: 0 4px 4px 0;
  background: var(--colorNav);
}

.sidebar {
  display: grid;
  position: relative;
/*   display: none; */
  border-radius: 4px 0 0 4px;
  background: var(--colorSidebar);
}

.nav > p, .sidebar > p {
  align-self: center;
}

.grid {
  background: var(--colorGrid);
}

.grid > div {
  display: grid;
  border: 1px dashed var(--colorColumnBorder);
  border-radius: 4px;
  background-color: var(--colorColumn);
  color: var(--colorColText);
}

.grid > div > p {
  align-self: center;
}

.handle {
  transition: all 0.25s ease;
  border-radius: 4px 0 0 4px;
  display: none;
  position: absolute;
  top: 0;
  height: 100%;
  width: 4px;
  background: var(--colorPrimaryInteraction);
}

.handle:hover{
  background: var(--colorSecondaryInteraction);
}

/* Grid */
/* >= 320px 4col */
.wrapper {
  margin: var(--marginSize);
  display: grid;
  height: 100vh;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 96px 80px 1fr;
  column-gap: var(--gutterSize);
  row-gap: 16px;
  grid-template-areas:
    "menu menu menu menu"
    "nav nav sidebar sidebar"
    "grid grid grid grid";
}

.navToggle,
.sidebarToggle {
  display: none;
}

.grid > div:nth-child(n + 5):nth-child(-n + 12) {
  display: none;
}

.menu {
  grid-area: menu;
}

.nav {
  grid-area: nav;
}

.sidebar {
  grid-area: sidebar;
}

.grid {
  display: grid;
  grid-area: grid;
  column-gap: var(--gutterSize);
  grid-template-columns: repeat(var(--colNumber), minmax(0, 1fr));
}

.grid > div {
  min-width: 0;
  width: 100%;
  grid-column: span var(--colWidth);
}

/* >= 600px 6col */
@media only screen and (min-width: 600px) {
  .grid > div:nth-child(n + 5):nth-child(-n + 6) {
    display: grid;
  }

  :root {
    --gutterSize: 24px;
    --marginSize: 0 24px;
    --colNumber: 6;
  }

  .handle {
    display: none;
  }
}

/* >= 1024px 12col */
@media only screen and (min-width: 1024px) {
  .wrapper {
    grid-template-rows: 96px 1fr;
    grid-template-columns: var(--navSize) 1fr var(--sidebarSize);
    grid-template-areas:
      "menu menu menu"
      "nav grid sidebar";
  }

  :root {
    --gutterSize: 40px;
    --marginSize: 0;
    --colNumber: 12;
  }
  
  .handle {
    display: block;
  }
  
  .nav, .sidebar {
    display: grid;
  }

  .grid > div:nth-child(n + 7):nth-child(-n + 12) {
    display: grid;
  }

  .navToggle,
  .sidebarToggle {
    display: inline-block;
  }
  
.nav > p, .sidebar > p {
  transform: rotate(-90deg);
  align-self: center;
}
}
              
            
!

JS

              
                // Selector
let select = s => document.querySelector(s),
  selectAll = s => document.querySelectorAll(s),
  nav = select(".nav"),
  sidebar = select(".sidebar"),
  handle = select(".handle"),
  wrapper = select(".wrapper"),
  navToggle = select(".navToggle"),
  sidebarToggle = select(".sidebarToggle"),
  screenInfo = select(".screenInfo"),
  gridInfo = select(".gridInfo"),
  gridSize = select(".grid"),
  root = select(":root"),
  allCol = selectAll(".grid > div:nth-child(n+1):nth-child(-n+12)"),
  col5To12 = selectAll(".grid > div:nth-child(n+5):nth-child(-n+12)"),
  col7To12 = selectAll(".grid > div:nth-child(n+7):nth-child(-n+12)"),
  colText = selectAll(".grid p");

// Motion
TweenMax.fromTo([nav, gridSize, sidebar], 0.75, {opacity: 0, y: +10}, {opacity: 1, y: 0});
TweenMax.staggerFromTo(colText, 1, {opacity: 0, y: +10}, {opacity: 1, y: 0}, 0.025);

// Grid
function updateGridInfo() {
  return (gridInfo.innerHTML = "Grid container: " + gridSize.offsetWidth);
}

updateGridInfo();

// Screen size
let sidebarSize = sidebar.offsetWidth;
let screenWidth = window.innerWidth;
let screenHeight = window.innerHeight;

function updateScreenInfo() {
  return (screenInfo.innerHTML =
    "Screen: " + screenWidth + " x " + screenHeight);
}

updateScreenInfo();

// >= 1024: 12col --> 6col, 6col --> 4col
function checkGridSize() {
  let gridSizeValue = gridSize.offsetWidth;

  if (screenWidth > 1024) {
    if (gridSizeValue >= 768) {
      // console.log("1024: 12col");
      show12Col();
      root.style.setProperty("--colNumber", 12);
    } else if (gridSizeValue >= 480) {
      // console.log("1024: 6col");
      show6Col();
      root.style.setProperty("--colNumber", 6);
    } else if (gridSizeValue < 480) {
      // console.log("1024: 4col");
      show4Col();
      root.style.setProperty("--colNumber", 4);
    }
  } else if (screenWidth >= 600) {
    // console.log("576: 6col");
    show6Col();
    root.style.setProperty("--colNumber", 6);
  } else if (screenWidth < 600) {
    // cons;
ole.log("576: 4col");
    show4Col();
    root.style.setProperty("--colNumber", 4);
  }
}

// Show 4col
function show4Col() {
  allCol.forEach(function(obj) {
    obj.style.display = "grid";
  });
  col5To12.forEach(function(obj) {
    obj.style.display = "none";
  });
}

// Show  6col
function show6Col() {
  allCol.forEach(function(obj) {
    obj.style.display = "grid";
  });
  col7To12.forEach(function(obj) {
    obj.style.display = "none";
  });
}

// Show 12col
function show12Col(){
        allCol.forEach(function(obj) {
        obj.style.display = "grid";
      });
}

window.addEventListener("resize", () => {
  screenWidth = window.innerWidth;
  screenHeight = window.innerHeight;

  updateScreenInfo();
  updateGridInfo();
  checkGridSize();
});

// Resizable
let sidebarValue = sidebar.offsetWidth;
let handleZone = document.createElement("div");
let posX = 0;

Draggable.create(handleZone, {
  type: "x",
  trigger: handle,
  cursor: "ew-resize",
  onRelease: function() {
    // console.log(sidebarColor)
    TweenMax.to("html", 0.25, {
      "--colorSidebar": "#FFFFFF"
    });
  },
  onDrag: updateSidebar,
  onPress: function() {
    posX = this.x;
    TweenMax.to("html", 0.25, {
      "--colorSidebar": "#4C9AFF"
    });
  }
});

function updateSidebar() {
  let diffX = this.x - posX;
  posX = this.x;
  sidebarSize = clamp(sidebarSize - diffX, 64, 400);
  root.style.setProperty("--sidebarSize", sidebarSize + "px");
  sidebarValue = sidebar.offsetWidth;
  updateGridInfo();
  checkGridSize();
}

function clamp(value, min, max) {
  return Math.max(min, Math.min(value, max));
}

// Expand + collapse nav
function navCollapse() {
  // root.style.setProperty("--navSize", "64px");
TweenMax.to("html", 0.25, {"--navSize": "64px"});

  navToggle.innerHTML = "expand nav";
  checkGridSize();
  updateGridInfo();
}

function navExpand() {
  // root.style.setProperty("--navSize", "304px");
  TweenMax.to("html", 0.25, {"--navSize": "304px"});
  navToggle.innerHTML = "collapse nav";
  checkGridSize();
  updateGridInfo();
}

navToggle.addEventListener("click", () => {
  navToggle.setAttribute(
    "aria-pressed",
    navToggle.getAttribute("aria-pressed") === "true" ? "false" : "true"
  );
   nav.setAttribute(
    "aria-expanded",
    nav.getAttribute("aria-expanded") === "true" ? "false" : "true"
  );
  return (navToggle.tog = !navToggle.tog) ? navCollapse() : navExpand();
});

// Expand + collapse sidebar
function sidebarHide() {
  // root.style.setProperty("--sidebarSize", "0px");
  TweenMax.to("html", 0.25, {"--sidebarSize": "0px"});
  sidebarToggle.innerHTML = "show sidebar";
  checkGridSize();
  updateGridInfo();
}

function sidebarShow() {
  // root.style.setProperty("--sidebarSize", sidebarValue + "px");
  TweenMax.to("html", 0.25, {"--sidebarSize": sidebarValue + "px"});
  sidebarToggle.innerHTML = "hide sidebar";
  checkGridSize();
  updateGridInfo();
}

sidebarToggle.addEventListener("click", () => {
  sidebarToggle.setAttribute(
    "aria-pressed",
    sidebarToggle.getAttribute("aria-pressed") === "true" ? "false" : "true"
  );
    sidebar.setAttribute(
    "aria-hidden",
    sidebar.getAttribute("aria-hidden") === "true" ? "false" : "true"
  );
  return (sidebarToggle.tog = !sidebarToggle.tog) ? sidebarHide() : sidebarShow();
});

              
            
!
999px

Console