Forms

Simple CSS for HTML forms.

 /*csslint box-model:false*/

 /*
 Box-model set to false because we're setting a height on select elements,
 which also have border and padding. This is done because some browsers
 don't render the padding. We explicitly set the box-model for select
 elements to border-box, so we can ignore the csslint warning.
 */

Default Form

To create a default inline form, add the cw-form classname to any <form> element.

.cw-form input[type="text"],
.cw-form input[type="password"],
.cw-form input[type="email"],
.cw-form input[type="url"],
.cw-form input[type="date"],
.cw-form input[type="month"],
.cw-form input[type="time"],
.cw-form input[type="datetime"],
.cw-form input[type="datetime-local"],
.cw-form input[type="week"],
.cw-form input[type="number"],
.cw-form input[type="search"],
.cw-form input[type="tel"],
.cw-form input[type="color"],
.cw-form select,
.cw-form textarea {
    padding: 0.5em 0.6em;
    display: inline-block;
    border: 1px solid #ccc;
    box-shadow: inset 0 1px 3px #ddd;
    border-radius: 4px;
    vertical-align: middle;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

    /*
    Need to separate out the :not() selector from the rest of the CSS 2.1
    selectors since IE8 won't execute CSS that contains a CSS3 selector.
    */
.cw-form input:not([type]) {
    padding: 0.5em 0.6em;
    display: inline-block;
    border: 1px solid #ccc;
    box-shadow: inset 0 1px 3px #ddd;
    border-radius: 4px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}


    /* Chrome (as of v.32/34 on OS X) needs additional room for color to display. */
    /* May be able to remove this tweak as color inputs become more standardized across browsers. */
.cw-form input[type="color"] {
    padding: 0.2em 0.5em;
}


.cw-form input[type="text"]:focus,
.cw-form input[type="password"]:focus,
.cw-form input[type="email"]:focus,
.cw-form input[type="url"]:focus,
.cw-form input[type="date"]:focus,
.cw-form input[type="month"]:focus,
.cw-form input[type="time"]:focus,
.cw-form input[type="datetime"]:focus,
.cw-form input[type="datetime-local"]:focus,
.cw-form input[type="week"]:focus,
.cw-form input[type="number"]:focus,
.cw-form input[type="search"]:focus,
.cw-form input[type="tel"]:focus,
.cw-form input[type="color"]:focus,
.cw-form select:focus,
.cw-form textarea:focus {
    outline: 0;
    border-color: #129FEA;
}

    /*
    Need to separate out the :not() selector from the rest of the CSS 2.1 selectors
    since IE8 won't execute CSS that contains a CSS3 selector.
    */
.cw-form input:not([type]):focus {
    outline: 0;
    border-color: #129FEA;
}

.cw-form input[type="file"]:focus,
.cw-form input[type="radio"]:focus,
.cw-form input[type="checkbox"]:focus {
    outline: thin solid #129FEA;
    outline: 1px auto #129FEA;
}


.cw-form select {
    /* Normalizes the height; padding is not sufficient. */
    height: 2.25em;
    border: 1px solid #ccc;
    background-color: white;
}
.cw-form select[multiple] {
    height: auto;
}
.cw-form label {
    margin: 0.5em 0 0.2em;
}
.cw-form fieldset {
    margin: 0;
    padding: 0.35em 0 0.75em;
    border: 0;
}
.cw-form legend {
    display: block;
    width: 100%;
    padding: 0.3em 0;
    margin-bottom: 0.3em;
    color: #333;
    border-bottom: 1px solid #e5e5e5;
}

Stacked Form

To create a stacked form with input elements below the labels, add the cw-form-stacked classname to a <form> element alongside cw-form.

.cw-form-stacked input[type="text"],
.cw-form-stacked input[type="password"],
.cw-form-stacked input[type="email"],
.cw-form-stacked input[type="url"],
.cw-form-stacked input[type="date"],
.cw-form-stacked input[type="month"],
.cw-form-stacked input[type="time"],
.cw-form-stacked input[type="datetime"],
.cw-form-stacked input[type="datetime-local"],
.cw-form-stacked input[type="week"],
.cw-form-stacked input[type="number"],
.cw-form-stacked input[type="search"],
.cw-form-stacked input[type="tel"],
.cw-form-stacked input[type="color"],
.cw-form-stacked input[type="file"],
.cw-form-stacked select,
.cw-form-stacked label,
.cw-form-stacked textarea {
    display: block;
    margin: 0.25em 0;
}

    /*
    Need to separate out the :not() selector from the rest of the CSS 2.1 selectors
    since IE8 won't execute CSS that contains a CSS3 selector.
    */
.cw-form-stacked input:not([type]) {
    display: block;
    margin: 0.25em 0;
}

Aligned Form

To create an aligned form, add the cw-form-aligned classname to a <form> element alongside cw-form. In an aligned form, the labels are right-aligned against the form input controls, but on smaller screens revert to a stacked form.

.cw-form-aligned input,
.cw-form-aligned textarea,
.cw-form-aligned select,
.cw-form-message-inline {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    vertical-align: middle;
}
.cw-form-aligned textarea {
    vertical-align: top;
}

Control Groups for Aligned Forms

.cw-form-aligned .cw-control-group {
    margin-bottom: 0.5em;
}
.cw-form-aligned .cw-control-group label {
    text-align: right;
    display: inline-block;
    vertical-align: middle;
    width: 10em;
    margin: 0 1em 0 0;
}
.cw-form-aligned .cw-controls {
    margin: 1.5em 0 0 11em;
}

Multi-Column Form (with Pure Grids)

To create multi-column forms, include your form elements within a Pure Grid. Creating responsive multi-column forms (like the example below) requires Pure Responsive Grids to be present on the page.

Rounded Inputs

To display a form control with rounded corners, add the cw-input-rounded classname.

.cw-form input.cw-input-rounded,
.cw-form .cw-input-rounded {
    border-radius: 2em;
    padding: 0.5em 1em;
}

Grouped Inputs

To group sets of text-based input elements, wrap them in a <fieldset> element with a cw-group classname. Grouped inputs work well for sign-up forms and look natural on mobile devices.

.cw-form .cw-group fieldset {
    margin-bottom: 10px;
}
.cw-form .cw-group input,
.cw-form .cw-group textarea {
    display: block;
    padding: 10px;
    margin: 0 0 -1px;
    border-radius: 0;
    position: relative;
    top: -1px;
}
.cw-form .cw-group input:focus,
.cw-form .cw-group textarea:focus {
    z-index: 3;
}
.cw-form .cw-group input:first-child,
.cw-form .cw-group textarea:first-child {
    top: 1px;
    border-radius: 4px 4px 0 0;
    margin: 0;
}
.cw-form .cw-group input:first-child:last-child,
.cw-form .cw-group textarea:first-child:last-child {
    top: 1px;
    border-radius: 4px;
    margin: 0;
}
.cw-form .cw-group input:last-child,
.cw-form .cw-group textarea:last-child {
    top: -2px;
    border-radius: 0 0 4px 4px;
    margin: 0;
}
.cw-form .cw-group button {
    margin: 0.35em 0;
}

Input Sizing

Input elements have fluid width sizes in a syntax that is similar to Pure Grids. You can apply a cw-input-* class to these elements.

You can control input sizing even further by wrapping them in grid containers. In the example below, the elements have a cw-input-1 class, but are wrapped in a <div> with a specific grid class.

Required Inputs

To mark a form control as required, add the required attribute.

.cw-form .cw-input-1 {
    width: 100%;
}
.cw-form .cw-input-2-3 {
    width: 66%;
}
.cw-form .cw-input-1-2 {
    width: 50%;
}
.cw-form .cw-input-1-3 {
    width: 33%;
}
.cw-form .cw-input-1-4 {
    width: 25%;
}

Disabled Inputs

To disable a form control, add the disabled attribute.

.cw-form input[type="text"][disabled],
.cw-form input[type="password"][disabled],
.cw-form input[type="email"][disabled],
.cw-form input[type="url"][disabled],
.cw-form input[type="date"][disabled],
.cw-form input[type="month"][disabled],
.cw-form input[type="time"][disabled],
.cw-form input[type="datetime"][disabled],
.cw-form input[type="datetime-local"][disabled],
.cw-form input[type="week"][disabled],
.cw-form input[type="number"][disabled],
.cw-form input[type="search"][disabled],
.cw-form input[type="tel"][disabled],
.cw-form input[type="color"][disabled],
.cw-form select[disabled],
.cw-form textarea[disabled] {
    cursor: not-allowed;
    background-color: #eaeded;
    color: #cad2d3;
}

    /*
    Need to separate out the :not() selector from the rest of the CSS 2.1 selectors
    since IE8 won't execute CSS that contains a CSS3 selector.
    */
.cw-form input:not([type])[disabled] {
    cursor: not-allowed;
    background-color: #eaeded;
    color: #cad2d3;
}

Read-Only Inputs

To make a form input read-only, add the readonly attribute. The difference between disabled and readonly is read-only inputs are still focusable. This allows people to interact with the input and select its text, whereas disabled controls are not interactive.

.cw-form input[readonly],
.cw-form select[readonly],
.cw-form textarea[readonly] {
    background-color: #eee; /* menu hover bg color */
    color: #777; /* menu text color */
    border-color: #ccc;
}

.cw-form input:focus:invalid,
.cw-form textarea:focus:invalid,
.cw-form select:focus:invalid {
    color: #b94a48;
    border-color: #e9322d;
}
.cw-form input[type="file"]:focus:invalid:focus,
.cw-form input[type="radio"]:focus:invalid:focus,
.cw-form input[type="checkbox"]:focus:invalid:focus {
    outline-color: #e9322d;
}

Checkboxes and Radios

To normalize and align checkboxes and radio inputs, add the cw-checkbox or cw-radio classname.

.cw-form .cw-checkbox,
.cw-form .cw-radio {
    margin: 0.5em 0;
    display: block;
}

Inline help for forms

.cw-form-message-inline {
    display: inline-block;
    padding-left: 0.3em;
    color: #666;
    vertical-align: middle;
    font-size: 0.875em;
}

Block help for forms

.cw-form-message {
    display: block;
    color: #666;
    font-size: 0.875em;
}

Responsive forms

@media only screen and (max-width : 480px) {
    .cw-form button[type="submit"] {
        margin: 0.7em 0 0;
    }

    .cw-form input:not([type]),
    .cw-form input[type="text"],
    .cw-form input[type="password"],
    .cw-form input[type="email"],
    .cw-form input[type="url"],
    .cw-form input[type="date"],
    .cw-form input[type="month"],
    .cw-form input[type="time"],
    .cw-form input[type="datetime"],
    .cw-form input[type="datetime-local"],
    .cw-form input[type="week"],
    .cw-form input[type="number"],
    .cw-form input[type="search"],
    .cw-form input[type="tel"],
    .cw-form input[type="color"],
    .cw-form label {
        margin-bottom: 0.3em;
        display: block;
    }

    .cw-group input:not([type]),
    .cw-group input[type="text"],
    .cw-group input[type="password"],
    .cw-group input[type="email"],
    .cw-group input[type="url"],
    .cw-group input[type="date"],
    .cw-group input[type="month"],
    .cw-group input[type="time"],
    .cw-group input[type="datetime"],
    .cw-group input[type="datetime-local"],
    .cw-group input[type="week"],
    .cw-group input[type="number"],
    .cw-group input[type="search"],
    .cw-group input[type="tel"],
    .cw-group input[type="color"] {
        margin-bottom: 0;
    }

    .cw-form-aligned .cw-control-group label {
        margin-bottom: 0.3em;
        text-align: left;
        display: block;
        width: 100%;
    }

    .cw-form-aligned .cw-controls {
        margin: 1.5em 0 0 0;
    }

    /* NOTE: cw-help-inline is deprecated. Use .cw-form-message-inline instead. */
    .cw-form .cw-help-inline,
    .cw-form-message-inline,
    .cw-form-message {
        display: block;
        font-size: 0.75em;
        /* Increased bottom padding to make it group with its related input element. */
        padding: 0.2em 0 0.8em;
    }
}