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

Auto Save

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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <p style="font-size: 25px; font-weightL">CSS Grid Equal Columns!</p>
    <p>1fr 1fr 1fr works, but there are some gotchas!</p>

    <div class="a container">
      <div>
        <span class="columnSize">1fr</span>
      </div>
      <div>
        <span class="columnSize">1fr</span>
      </div>
      <div>
        <span class="columnSize">1fr</span>
      </div>
    </div>

    <div class="b container">
      <div>
        <span class="columnSize">1fr</span>
      </div>
      <div>
        <span class="columnSize">1fr<br /></span>
        <p>
          I have more content in me, but since there are spaces I will wrap!
          Columns are still the same width
        </p>
      </div>
      <div>
        <span class="columnSize">1fr</span>
      </div>
    </div>

    <div class="c container">
      <div>
        <span class="columnSize">1fr<br /></span>
        But if something causes me to be larger - like an image. I'll take that
        space up before the fr (free space) is distributed.
        <img src="https://source.unsplash.com/random/600x50" alt="" />
      </div>
      <div>
        <span class="columnSize">1fr<br /></span>
      </div>
      <div>
        <span class="columnSize">1fr</span>
      </div>
    </div>
    <div class="c container">
      <div>
        <span class="columnSize">1fr<br /></span>
      </div>
      <div>
        <span class="columnSize">1fr<br /></span>
        <p>unbrokenTextCanAlsoCauseTheElementToGrowLargerAndLargerAndLarger</p>
      </div>

      <div>
        <span class="columnSize">1fr</span>
      </div>
    </div>

    <div class="d container">
      <div>
        <span class="columnSize">1fr<br /></span>
        <p class="fix">Fix:</p>
        max-width: 100%; on images
        <img src="https://source.unsplash.com/random/800x50" alt="" />
      </div>
      <div>
        <span class="columnSize">1fr<br /></span>
        <p class="fix">Fix:</p>
        <p>word-wrap or overflow scroll/hidden</p>
        <p>unbrokenTextCanAlsoCauseTheElementToGrowLargerAndLargerAndLarger</p>
      </div>
      <div>
        <span class="columnSize">1fr</span>
      </div>
    </div>

    <div class="e container">
      <div>
        <span class="columnSize">minmax(0, 1fr)<br /></span>
        minmax will ensure the columns stay equal, but the above fixes are still
        needed to account for larger content.
        <img src="https://source.unsplash.com/random/800x50" alt="" />
      </div>
      <div>
        <span class="columnSize">minmax(0, 1fr)<br /></span>
        <p>unbrokenTextCanAlsoCauseTheElementToGrowLargerAndLargerAndLarger</p>
      </div>
      <div>
        <span class="columnSize">minmax(0, 1fr)</span>
      </div>
    </div>
    <h2>repeat(3, minmax(0, 1fr));</h2>
    <div class="f container">
      <div>
        <span class="columnSize">minmax(0, 1fr)<br /></span>
        minmax will ensure the columns stay equal, but the above fixes are still
        needed to account for larger content.
        <img src="https://source.unsplash.com/random/800x50" alt="" />
      </div>
      <div>
        <span class="columnSize">minmax(0, 1fr)<br /></span>
        <p>unbrokenTextCanAlsoCauseTheElementToGrowLargerAndLargerAndLarger</p>
      </div>
      <div>
        <span class="columnSize">minmax(0, 1fr)</span>
      </div>
    </div>

    <h2>repeat(auto-fit, minmax(0, 1fr));</h2>
    <div class="i container">
      <div>
        <span class="columnSize"></span>
      </div>
      <div>
        <span class="columnSize">Longboyyyyyyyyyyyyyyyy</span>
      </div>
      <div>
        <span class="columnSize">autoFit</span>
      </div>
      <div>
        <span class="columnSize">autoFit</span>
        <img src="https://source.unsplash.com/random/800x50" alt="" />
      </div>
      <div>
        <span class="columnSize"> autoFit </span>
      </div>
      <div>
        <span class="columnSize">autoFit</span>
      </div>
    </div>

    <div class="g container">
      <div>
        <span class="columnSize">33.33%</span>
      </div>
      <div>
        <span class="columnSize">33.33%</span>
        <br />
        percentages work if you aren't using grid gap, but you go "over budget"
        if you add gap to 100% width. Just like adding margin.
      </div>
      <div>
        <span class="columnSize">33.33%</span>
      </div>
    </div>
    <div class="h container">
      <div>
        <span class="columnSize">calc(33% - 20px)<br /></span>
        What about CSS calc()?!
      </div>
      <div>
        <span class="columnSize">calc(33% - 20px)<br /></span>
        <p>Three columns, two gaps. Comes up short.</p>
      </div>
      <div>
        <span class="columnSize">calc(33% - 20px)</span>
        <p>
          Doing the math also assumes you know how many columns ahead of time
        </p>
      </div>
    </div>


  </body>
</html>

              
            
!

CSS

              
                
      .columnSize {
        color: black;
        font-weight: 600;
        font-size: 20px;
      }

      body {
        font-family: "Operator Mono";
        font-weight: 200;
        font-size: 20px;
        text-align: center;
      }

      .container {
        position: relative;
        max-width: 1000px;
        margin: 0 auto;
      }
      .container:before,
      .container:after {
        content: "";
        display: block;
        width: 2px;
        height: 290%;
        position: absolute;
        left: -2px;
        top: -200px;
        /* border-left: 3px dashed #272727ee; */
        background: linear-gradient(to bottom, transparent 50%, #000000aa 50%);
        background-size: 100% 50px;
        z-index: 2;
        display: none;
      }
      .container:after {
        right: -2px;
        left: auto;
      }

      .container > div {
        border: 2px solid black;
        border-radius: 20px;
        text-align: center;
        padding: 10px;
        margin-bottom: 20px;
      }

      .container.a {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 1fr 1fr 1fr;
      }

      .container.b {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 1fr 1fr 1fr;
      }

      .container.c {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 1fr 1fr 1fr;
      }

      .container.d {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 1fr 1fr 1fr;
      }

      .d img {
        max-width: 100%;
      }

      .d {
        word-wrap: anywhere;
      }

      .container.e {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
      }

      .container.f {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        word-wrap: anywhere;
      }

      .f > div {
        border-color: #ffc600;
        border-width: 4px;
      }

      .f img {
        max-width: 100%;
      }

      .container.g {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 33.33% 33.33% 33.33%;
      }

      .container.h {
        display: grid;
        grid-template-columns:
          calc(33% - 20px) calc(33% - 20px)
          calc(33% - 20px);
        gap: 20px;
      }
      .container.i {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
        gap: 20px;
      }

      .container.i > div {
        word-wrap: break-word;
        border-color: #ffc600;
        border-width: 4px;
        img {
          max-width: 100%;
        }
      }

      h2 {
        margin: 0;
        font-size: 20px;
      }

      /*
  Oh Hello!

  These are some base styles so that our tutorial looks good.

  Let's go through the important bits real quick
*/
      :root {
        --yellow: #ffc600;
        --black: #272727;
      }

      html {
        /* border-box box model allows us to add padding and border to our elements without increasing their size */
        box-sizing: border-box;
        /* A system font stack so things load nice and quick! */
        font-family: "Operator", -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji",
          "Segoe UI Emoji", "Segoe UI Symbol";
        font-weight: 900;
        font-size: 10px;
        color: var(--black);
        text-shadow: 0 2px 0 rgba(0, 0, 0, 0.07);
      }

      /*
  WAT IS THIS?!
  We inherit box-sizing: border-box; from our <html> selector
  Apparently this is a bit better than applying box-sizing: border-box; directly to the * selector
*/
      *,
      *:before,
      *:after {
        box-sizing: inherit;
      }

      body {
        /* background-image: url("./images/topography.svg"),
          linear-gradient(110deg, #f93d66, #6d47d9); */
        background-size: 340px, auto;
        min-height: calc(100vh - 100px);
        margin: 50px;
        /* background: white; */
        background-attachment: fixed;
        letter-spacing: -1px;
      }

      h1,
      h2,
      h3,
      h4,
      h5,
      h6 {
        margin: 0 0 5px 0;
      }

      /* Each item in our grid will contain numbers */
      .item {
        /* We center the contents of these items. You can also do this with flexbox too! */
        display: grid;
        justify-content: center;
        align-items: center;
        border: 5px solid rgba(0, 0, 0, 0.03);
        border-radius: 3px;
        font-size: 35px;
        background-color: var(--yellow);
        /* best colour */
      }

      .item p {
        margin: 0 0 5px 0;
      }

      .fix {
        margin: 0;
        font-weight: 900;
      }
    
              
            
!

JS

              
                
              
            
!
999px

Console