cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div class="container">

  <section class="demo">
    <h1>Form Elements in a CSS Grid</h1>
    
    <!-- two images -->
<!--     <div class="grid">
      <img src="http://fillmurray.com/400/300">
      <img src="http://fillmurray.com/400/300">
    </div>
 -->
    <!-- two number inputs -->
    <div class="grid">
      <input type="number">
      <input type="number">
    </div>

    <!-- two progress elements -->
    <div class="grid">
      <progress></progress>
      <progress></progress>
    </div>

    <!-- two naked inputs -->
    <div class="grid">
      <input>
      <input>
    </div>
    <!-- short select boxes -->
    <div class="grid">
      <select><option>Foo</option></select>
      <select><option>Bar</option></select>
    </div>
    <!-- long select boxes -->
    <div class="grid">
      <select><option>this is a really wide select box</option></select>
      <select><option>this is a really wide select box</option></select>
    </div>
    <!-- inputs in divs -->
    <div class="grid">
      <div><input></div>
      <div><input></div>
    </div>
    <!-- selects in divs -->
    <div class="grid">
      <div><select><option>this is a really wide select box</option></select></div>
      <div><select><option>this is a really wide select box</option></select></div>
    </div>

    <!-- file inputs -->
    <div class="grid">
      <input type="file">
      <input type="file">
    </div>
    <!-- submit buttons -->
    <div class="grid">
      <input type="submit">
      <input type="submit">
    </div>
    <!-- submit buttons -->
    <div class="grid">
      <input type="reset">
      <input type="reset">
    </div>
    <!-- short buttons -->
    <div class="grid">
      <button>Howdy</button>
      <button>Howdy</button>
    </div>

    <!-- long buttons -->
    <div class="grid">
      <button>Howdy There Pardner How Are You Doing?</button>
      <button>Howdy There Pardner How Are You Doing?</button>
    </div>
    <!-- buttons inside divs -->
    <div class="grid">
      <div><button>Howdy There Pardner How Are You Doing?</button></div>
      <div><button>Howdy There Pardner How Are You Doing?</button></div>
    </div>

  </section>
 
  <header>
    <p>TIL <code>input</code> elements in a CSS Grid will cause CSS Grids to lose their responsiveness. You can fix in Chrome by removing the min-width (which doesn't appear to be specified in Inspector). Text/images squeeze as expected. Repro:</p>

    <ul>
      <li>Resize window until horizontal scrollbars appear</li>
      <li><strong>Expected:</strong> No horizontal scrollbars, content keeps shrinking.</li>
      <li><strong>Actual:</strong> Inputs stops squeezing and horizontal scrollbar appears at ~.
    </ul>
    <p>Step 1: Remove `min-width: auto` from Grid Items</p>
    <button id="removeMinWidth">Apply min-width: 0 to Grid Items</button>
    <p>Step 2: Add Max Widths</p>
    <button id="addMaxWidth">Add max-widths to form controls</button>
    <p>Step 3: Make file and submit input text wrap</p>
    <button id="wrapText">Make input text wrap </button>
    <p>Step 4: Make range, number, and progress full-width</p>
    <button id="width100">Make rando controls full-width</button>
    <p>If you go one step further and make input/select widths `width: 100%`, then Steps 1 & 2 are redundant and not needed. But Step 1 fixes another issue (`overflow-x` elements) and Step 2 seems like a sensible default.</p>
  </header>
</div>
            
          
!
            
              // RESET
* {
  box-sizing: border-box;
}

header {
  background: #fee;
  padding: 1em;
  margin-bottom: 2em;
}

.container {
  padding: 2em;
  max-width: 1234px;
  margin: 0 auto;
}

button.active {
  background: green;
  color: white;
}


.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 2em;
  margin-bottom: 1em;
}

body.removeMinWidth {
  // &:before {
  //   content: '.grid > * { min-width: 0; }';
  //   position: fixed;
  //   background: red;
  //   top: 0;
  // }
  .grid > * {
    min-width: 0;
  }
}


body.addMaxWidth {
  img,
  video,
  audio,
  canvas,
  input,
  select,
  button,
  progress {
    max-width: 100%;
  }
}


body.wrapText {

  input { 
      white-space: pre-wrap;
  }

}


body.width100 {

  input[type="range"],
  progress { 
      width: 100%;
  }
  
  @supports (--moz-appearance: none) {
    input[type="number"] { width: 100%; }
  }
  // Override "intrinsic sizing" of replaced elements.
}
            
          
!
            
              document.querySelector('button#removeMinWidth').addEventListener('click', function( event ){
  event.preventDefault();
  document.body.classList.toggle('removeMinWidth');  
    this.classList.toggle('active');

});


document.querySelector('button#addMaxWidth').addEventListener('click', function( event ){
  event.preventDefault();
  document.body.classList.toggle('addMaxWidth');
    this.classList.toggle('active');

})


document.querySelector('button#wrapText').addEventListener('click', function( event ){
  event.preventDefault();
  document.body.classList.toggle('wrapText');
  this.classList.toggle('active');
})


document.querySelector('button#width100').addEventListener('click', function( event ){
  event.preventDefault();
  document.body.classList.toggle('width100');
    this.classList.toggle('active');

})

            
          
!
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.
Loading ..................

Console