Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="hex-wrap hex-group-1">
  <div class="hexagons">
    <div class="hex hex1"><a href="#" aria-label="Some label for screen readers"><span>1</span></a></div>
    <div class="hex hex2"><a href="#" aria-label="Some label for screen readers"><span>2</span></a></div>
    <div class="hex hex3"><a href="#" aria-label="Some label for screen readers"><span>3</span></a></div>
    <div class="hex hex4"><a href="#" aria-label="Some label for screen readers"><span>4</span></a></div>
    <div class="hex hex5"><a href="#" aria-label="Some label for screen readers"><span>5</span></a></div>
    <div class="hex hex6"><a href="#" aria-label="Some label for screen readers"><span>6</span></a></div>
    <div class="hex hex7"><a href="#" aria-label="Some label for screen readers"><span>7</span></a></div>
  </div>
</div>

<div class="hex-wrap hex-group-2">
  <div class="hexagons">
    <div class="hex hex1"><a href="#" aria-label="Some label for screen readers"><span>1</span></a></div>
    <div class="hex hex2"><a href="#" aria-label="Some label for screen readers"><span>2</span></a></div>
    <div class="hex hex3"><a href="#" aria-label="Some label for screen readers"><span>3</span></a></div>
    <div class="hex hex4"><a href="#" aria-label="Some label for screen readers"><span>4</span></a></div>
    <div class="hex hex5"><a href="#" aria-label="Some label for screen readers"><span>5</span></a></div>
    <div class="hex hex6"><a href="#" aria-label="Some label for screen readers"><span>6</span></a></div>
    <div class="hex hex7"><a href="#" aria-label="Some label for screen readers"><span>7</span></a></div>
  </div>
</div>
            
          
!
            
              .hex {
  background: black;
  color: white;
}

@mixin place($row, $col, $dir: 'ew') {
  height: calc(var(--hexwidth) * var(--hexvertex));
  @if $dir == 'ns' {
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);;
    top: calc(var(--hexwidth) * var(--hexside) * #{$row });
    left: calc(50% + var(--hexwidth) * #{($col * .5) - .5});
  }
  
  @elseif $dir == 'ew' {
    clip-path: polygon(75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%, 25% 0);
    top: calc(var(--hexwidth) * #{$row * .5 } * var(--hexvertex));
    left: calc(50% + var(--hexwidth) * #{($col * .75 ) - .5});
  } 
}

@mixin gridheight($num) {
  height: calc(var(--hexwidth) * var(--hexvertex) * #{$num});
}

.hex-wrap {
  position: relative;
  width: 90vw;
  margin: 0 auto;
  max-width: 1200px;
}

.hexagons {
  // The hexagons are positioned in relation to this element, so we need to tell it where to go.
  position: absolute;
  display: inline-block;
  margin: 0 auto;
}

.hex-group-1 {
    // We're going to use absolute positioning, so we need to wrap the whole thing to give it a height.
  --hexwidth: 50vw;            // Short vertex. This can be anything.
  --hexside: 1.154;             // Length of a side. This is intrinsic to a regular hexagon. It doesn't change.
  --hexvertex: .866; // Long vertex. This also doesn't change.
  --hexagon: polygon(75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%, 25% 0); // This is our hexagon
  
  @include gridheight(4);
  
  .hexagons {
    left: calc(25% * var(--hexside));
    
    @media (min-width: 600px) {
      left: calc(50%);
    }
  }
  
  .hex1 { @include place(0,0, 'ew'); }
  .hex2 { @include place(1,1, 'ew'); }
  .hex3 { @include place(2,0, 'ew'); }
  .hex4 { @include place(3,1, 'ew'); }
  .hex5 { @include place(4,0, 'ew'); }
  .hex6 { @include place(5,1, 'ew'); }
  .hex7 { @include place(6,0, 'ew'); }

  @media (min-width: 600px) {
    --hexwidth: calc(25vw * var(--hexside));
    @include gridheight(3);
    
    .hex1 { @include place(0,0, 'ew'); }
    .hex2 { @include place(1,1, 'ew'); }
    .hex3 { @include place(1,-1, 'ew'); }
    .hex4 { @include place(3,-1, 'ew'); }
    .hex5 { @include place(2,0, 'ew'); }
    .hex6 { @include place(4,0, 'ew'); }
    .hex7 { @include place(3,1, 'ew'); }
  }
  
  @media (min-width: 1200px) {
    --hexwidth: calc(300px * var(--hexside));
  }

}

.hex-group-2 {
    // We're going to use absolute positioning, so we need to wrap the whole thing to give it a height.
  --hexwidth: 45vw;            // Short vertex. This can be anything.
  --hexside: .866;             // Length of a side. This is intrinsic to a regular hexagon. It doesn't change.
  --hexvertex: 1.155; // Long vertex. This also doesn't change.
  --hexagon: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); // This is our hexagon
   height: calc(var(--hexwidth) * var(--hexvertex) * 4);
    @include gridheight(4);
  
  .hexagons {
    left: 50%;
    @media (min-width: 600px) {
      // When we rearrange the hexagons, we need to move the starting point.
      // Where we put it depends on how many columns of hexagons we have.
      left: calc(50% - (var(--hexwidth) / 2));
    }
  }
    
  .hex1 { @include place(0,0,'ns'); }
  .hex2 { @include place(1,1,'ns'); }
  .hex3 { @include place(1,-1,'ns'); }
  .hex4 { @include place(3,-1,'ns'); }
  .hex5 { @include place(2,0,'ns'); }
  .hex6 { @include place(3,1,'ns'); }
  .hex7 { @include place(4,0,'ns'); }

  @media (min-width: 600px) {
    --hexwidth: 30vw;
    @include gridheight(2.5);
    
    .hex1 { @include place(0,0,'ns'); }
    .hex2 { @include place(0,2,'ns'); }
    .hex3 { @include place(1,-1,'ns'); }
    .hex4 { @include place(2,0,'ns'); }
    .hex5 { @include place(1,1,'ns'); }
    .hex6 { @include place(2,2,'ns'); }
    .hex7 { @include place(1,3,'ns'); }
  }
  
  @media (min-width: 1200px) {
    --hexwidth: 300px;
  }
}

.hex {
  // clip-path: var(--hexagon);
  width: var(--hexwidth);
  // height: calc(var(--hexwidth) * var(--hexvertex));
  position: absolute;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  align-items: stretch; 
  transform: scale(.9); // Remove the scaling to make the hexagons connect
  
  &:hover {
    transform: scale(.95);
    transition: .2s transform ease-in-out;
  }
}


// Everything below is just for demo purposes. It all works without these styles.
body {
  margin: 20px;
}

:root {
  --dark-green: #126479;
  --light-green: #9bc1b4;
  --purple-1: #a94a8f;
  --purple-2: #7e489b;
  --pink-1: #db92bf;
  --blue: #7092ae;
  --beige: #f5e9d1;
  --light-gray: #efefef;
}

// These aren't needed for styling, just for a visual reference.
.hex {
  // This is fun to watch as you resize, but not really necessary.
  transition: .5s all ease-in-out;

  a {
    display: grid;
    place-items: center;
    color: white;
    font-weight: bold;
    font-size: 3em;
    text-decoration: none;
  }
}

.hex1 { background: linear-gradient(to bottom, var(--light-green), var(--blue)); }
.hex2 { background: linear-gradient(to bottom, var(--light-green), var(--blue));  }
.hex3 { background: linear-gradient(to bottom, var(--light-green), var(--blue)); }
.hex4 { background: linear-gradient(to bottom, var(--light-green), var(--blue)); }
.hex5 { background: linear-gradient(to bottom, var(--light-green), var(--dark-green)); }
.hex6 { background: linear-gradient(to bottom, var(--purple-1), var(--purple-2)); }
.hex7 { background: linear-gradient(to bottom, var(--purple-1), var(--purple-2)); }

.hex-wrap {
  // This shows the height of the container.
  outline: 1px solid fuchsia;
  margin-bottom: 2em;
  
  @media (min-width: 600px) {
    outline: 1px solid lime;
  }
  
  @media (min-width: 1200px) {
    outline: 1px solid cyan;
  }
}

.hexagons {
  // This shows the center line of the 0,0 position in the grid.
  border-left: 1px solid fuchsia;
  top: 0;
  bottom: 0;
  filter: drop-shadow(0 3px 6px rgba(black, .1)) drop-shadow(0 2px 1px rgba(black, .3));
  
  @media (min-width: 600px) {
    border-left: 1px solid lime;
  }
  
  @media (min-width: 1200px) {
    border-left: 1px solid cyan;
  }
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console