css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <h1>Styling Forms</h1>
<h2>If <code>[type=textish]</code>, <code>[type=buttonish]</code>, &amp; <code>[type=togglable]</code> Existed in CSS</h2>

<!--

HTML has a lot of great input types, but it's hard to style all of them the way you want without accidentally styling other things. The dozen input types, checkboxes, radio buttons, select boxes, textareas - all of these elements really only fall three 'categories' of input that we can grab and style accordingly:

- textish
- buttonish
- togglable

So why can't we style all things that look like <input type=text> with something like: input[type=textish]?

This is my experiment to see if there are more effective ways of selecting input elements to style them.

I created a list of selectors we want to target in JavaScript, and then used EQCSS to allow us to use that variable name in our CSS and insert the entire list of selectors. This also allows us to write functions that alter how that list of selectors is returned to us, so we can easily add :hover, :focus, :active and other modifications to our selectors fairly easily.

-->

<!-- Text-like -->
<input type=hidden placeholder=hidden>
<input type=text placeholder=text>
<input type=search placeholder=search>
<input type=tel placeholder=tel>
<input type=url placeholder=url>
<input type=email placeholder=email>
<input type=password placeholder=password>
<input type=date placeholder=date>
<input type=month placeholder=month>
<input type=week placeholder=week>
<input type=time placeholder=time>
<input type=datetime-local placeholder=datetime-local>
<input type=number placeholder=number>
<input type=range placeholder=range>
<input type=color placeholder=color>
<textarea>textarea</textarea>

<!-- Toggle-like -->
<input type=checkbox value=checkbox>
<input type=checkbox value=checkbox>
<input type=checkbox value=checkbox>
<input type=radio name=radio value=radio>
<input type=radio name=radio value=radio>
<input type=radio name=radio value=radio>

<!-- Button-like-->
<input type=file value=file>
<input type=submit value=submit>
<input type=reset value=reset>
<input type=button value=button>
<button>real button</button>
<select>
  <option>option</option>
  <option>option</option>
  <option>option</option>
</select>
            
          
!
            
              @element input, textarea, select, button {

  /* set width for most inputs */
  eval('textish'),
  [type=range],
  [type=file],
  textarea,
  select {
    display: block;
    width: 100%;
  }

  /* Give default style to text inputs and buttons */
  eval('textish'),
  eval('buttonish'),
  eval('togglable'),
  select {
    -webkit-appearance: none;
    appearance: none;
    padding: .5em;
    min-height: 2em;
    margin: .5em 0;
    color: #555;
    background-color: white;
    border: 1px solid rgba(0,0,0,.3);
    border-radius: 0;
    line-height: 1;
    font-size: 12pt;
    font-weight: 400;
    font-family: 'Source Sans', sans-serif;
  }

  /* Set border radius on buttons and select */
  eval('buttonish'),
  select {
    min-height: 0;
    border-radius: 3px;
    cursor: pointer;
  }

  /* enhance button styles */
  eval('buttonish') {
    background-color: transparent;
  }

  /* size togglable inputs */
  eval('togglable') {
    min-height: 1em;
    display: inline-block;
    cursor: pointer;
  }
  [type=radio] {
    border-radius: 100%;
  }
  eval('action("checked",togglable)') {
    background-color: #999;
    box-shadow: inset white 0 1px 0,
                inset white 1px 0 0,
                inset white -1px 0 0,
                inset white 0 -1px 0;
  }
  /* add min-height to textarea */
  textarea {
    min-height: 5em;
  }

  /* enhance select */
  select {
    padding-right: 1.5em;
    text-indent: 0.01px;
    text-overflow: '';
    background-repeat: no-repeat;
    background-position: calc(100% - .5em) 50%;
    background-size: 12px;
    background-image: url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E %3Cpolygon opacity='0.6' points='0,4 16,4 8,12'/%3E %3C/svg%3E ");
  }
  select::-ms-expand {
    display: none;
  }

  /* input & select hover styles */
  eval("action('hover',textish)"),
  eval("action('hover',togglable)"),
  select:hover {
    border: 1px solid gold;
  }

  /* input & select focus styles */
  eval("action('focus',textish)"),
  select:focus {
    background-color: lightyellow;
  }

  /* button hover styles */
  eval("action('hover',buttonish)") {
    color: white;
    background-color: #999;
  }

  /* button focus styles */
  eval("action('active',buttonish)") {
    color: white;
    background-color: #555;
  }

  /* fix type=search padding */
  [type=search] {
    padding-right: 0;
  }
}
            
          
!
            
              /* selector lists */
var textish = [
  '[type=text]', '[type=search]', '[type=tel]', '[type=url]', '[type=email]', '[type=password]', '[type=date]', '[type=month]', '[type=week]', '[type=time]', '[type=datetime-local]', '[type=number]', '[type=color]', 'textarea'
]
var togglable = [
  '[type=checkbox]', '[type=radio]'
]
var buttonish = [
  '[type=submit]', '[type=reset]', '[type=button]', 'button'
]

/* return selectors with :states using action('state',arrayName) */
function action(state,array){
  var selectors ='';
  for(i=0;i<array.length;i++){
    selectors += array[i]+':'+state
    if (i<array.length-1) {
      selectors += ', '
    }
  }
  return selectors
}
            
          
!
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