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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              // Fonts
// ----------------------------------------------
@import url('https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i');

$root-font-size: 16;

// Breakpoints
// ----------------------------------------------
$breakpoint-small: 34em !default;  // 544px
$breakpoint-medium: 48em !default; // 768px
$breakpoint-large: 64em !default;  // 1024px
$breakpoint-xlarge: 90em !default; // 1440px

// Mixins
// ----------------------------------------------
@function rem($values) {
  $rems: ();

  @each $value in $values {
      @if $value == 0 or $value == auto {
          $rems: append($rems, $value);
      } @else {
          $rems: append(
              $rems,
              ($value / $root-font-size) + rem
          );
      }
  }

  @return $rems;
}

@function pixify($values) {
    $pxs: ();

    @each $value in $values {
        @if $value == 0 or $value == auto {
            $pxs: append($pxs, $value);
        } @else {
            $pxs: append(
                $pxs,
                $value + px
            );
        }
    }

    @return $pxs;
}

body, * {
  box-sizing: border-box;
  color: #222;
  font-family: 'PT Sans', Arial, Helvetica, sans-serif;
  font-size: pixify($root-font-size);
}

a {
  color: #1B6FA0;
}

b, strong {
  font-weight: 700;
}

.page {
  padding: rem(24);
}

// Grid
// ----------------------------------------------

// Set the number of columns you want to use on your layout.
$grid-columns: 12 !default;

// Set the gutter between columns.
$grid-gutter-width: 1rem !default;

// Create or remove breakpoints for your project
// Syntax:
// name SIZErem,
$grid-breakpoints: small $breakpoint-small,
  medium $breakpoint-medium,
  large $breakpoint-large !default;

$grid-gutter-compensation: $grid-gutter-width * .5 * -1;

$grid-half-gutter-width: $grid-gutter-width * .5;

.l-grid {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  margin-left: $grid-gutter-compensation;
  margin-right: $grid-gutter-compensation;
  flex: 0 1 auto;
  flex-wrap: wrap;

  &--collapsed {
    > .l-grid__col {
      padding: 0 $grid-half-gutter-width;
    }
  }
}

.l-grid__col {
  width: 100%;
  box-sizing: border-box;
  padding: $grid-half-gutter-width;
}

@for $i from 1 through $grid-columns {
  .l-grid__col--#{$i} {
    flex-basis: 100% / $grid-columns * $i;
    max-width: 100% / $grid-columns * $i;
  }
}
@for $i from 1 through $grid-columns {
  .l-grid__col--offset-#{$i} {
    margin-left: 100% / $grid-columns * $i;
  }
}

.l-grid--start {
  text-align: start;
  justify-content: flex-start;
}

.l-grid--center {
  text-align: center;
  justify-content: center;
}

.l-grid--end {
  text-align: end;
  justify-content: flex-end;
}

.l-grid--top {
  align-items: flex-start;
}

.l-grid--middle {
  align-items: center;
}

.l-grid--bottom {
  align-items: flex-end;
}

.l-grid--around {
  justify-content: space-around;
}

.l-grid--between {
  justify-content: space-between;
}

.l-grid--stretch {
  align-items: stretch;
}


@each $breakpoint in $grid-breakpoints {
  $name: nth($breakpoint, 1);
  $size: nth($breakpoint, 2);

  @media only screen and (min-width: $size) {

    @for $i from 1 through $grid-columns {
      .l-grid__col--#{$i}\@#{$name} {
        flex-basis: 100% / $grid-columns * $i;
        max-width: 100% / $grid-columns * $i;
      }
    }

    @for $i from 1 through $grid-columns {
      .l-grid__col--offset-#{$i}\@#{$name} {
        margin-left: 100% / $grid-columns * $i;
      }
    }

    .l-grid--start\@#{$name} {
      justify-content: flex-start;
      text-align: start;
    }

    .l-grid--center\@#{$name} {
      justify-content: center;
      text-align: center;
    }

    .l-grid--end\@#{$name} {
      justify-content: flex-end;
      text-align: end;
    }

    .l-grid--top\@#{$name} {
      align-items: flex-start;
    }

    .l-grid--middle\@#{$name} {
      align-items: center;
    }

    .l-grid--bottom\@#{$name} {
      align-items: flex-end;
    }

    .l-grid--around\@#{$name} {
      justify-content: space-around;
    }

    .l-grid--between\@#{$name} {
      justify-content: space-between;
    }

  }
}

// Forms
// ----------------------------------------------
input[type="text"],
textarea {
  background-color: #f5f5f5;
  border: 1px solid #ccc;
  font-size: rem(16);
  padding: rem(10);
  width: 100%;
}

textarea {
  min-height: rem(100);
  resize: none;
}

select {
  background: #f5f5f5 right top no-repeat url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCA0NTUgNDU1IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NTUgNDU1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgd2lkdGg9IjUxMnB4IiBoZWlnaHQ9IjUxMnB4Ij4KPHBhdGggZD0iTTAsMHY0NTVoNDU1VjBIMHogTTIyNy41LDMwNy4yMzdMOTkuNDExLDE3OS41NjVsMjEuMTc4LTIxLjI0OEwyMjcuNSwyNjQuODhsMTA2LjkxMS0xMDYuNTYzbDIxLjE3OCwyMS4yNDhMMjI3LjUsMzA3LjIzN3ogICIgZmlsbD0iIzFiNmZhMCIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K');
  background-size: contain;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: rem(1) solid #ccc;
  border-radius: 0;
  display: block;
  padding: rem(10);
  width: 100%;
}

select:-moz-focusring {
  outline: none;
  border: none;
}

.error-text {
  color: #cf102d;
  display: none;
  font-size: rem(14);
  padding-top: rem(5);
}

input,
textarea,
select {
  
  &.has-error {
    border: rem(1) solid #cf102d;
  }
  
  &.has-error ~ .error-text {
    display: block;
  }
  
  &:focus {
    box-shadow: 0 0 0 rem(3) lighten(#1b6fa0, 50%);
    outline: 0;
  }
}

button {
  background: #333;
  border: 0;
  border-radius: rem(4);
  color: #fff;
  padding: rem(10 20);
}

label {
  display: inline-block;
  font-size: rem(14);
  font-weight: 700;
  margin-bottom: rem(3);
}

legend {
  font-size: rem(24);
  font-weight: 700;
  margin-bottom: rem(16);
}

.form {
  width: auto;
  
  @media (min-width: $breakpoint-medium) {
    max-width: 824px;
  }
}
            
          
!
            
              const { Component, PropTypes } = React;
const { render } = ReactDOM;

const personalInfoFields = [
  {
    colSize: '5',
    type: 'text',
    id: 'first-name' ,
    name: 'firstName',
    label: 'First Name',
    defaultValue: 'John',
    errorText: 'First name is required',
    required: true, 
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '5',
    type: 'text',
    id: 'last-name' ,
    name: 'lastName',
    label: 'Last Name',
    defaultValue: 'Smith',
    errorText: 'Last name is required',
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '2',
    type: 'text',
    id: 'mi' ,
    name: 'mi',
    label: 'MI',
    defaultValue: 'F',
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '6',
    type: 'text',
    id: 'email' ,
    name: 'email',
    label: 'Email',
    defaultValue: 'j.smith@gmail.com',
    errorText: 'Email address is required',
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '6',
    type: 'text',
    id: 'phone' ,
    name: 'phone',
    label: 'Phone',
    maxlength: 12,
    defaultValue: '224-622-9208',
    errorText: 'Phone number is required',
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '7',
    type: 'text',
    id: 'city' ,
    name: 'city',
    label: 'City',
    defaultValue: 'Buffalo Grove',
    errorText: 'City is required',
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    colSize: '2',
    type: 'select',
    id: 'state' ,
    name: 'state',
    label: 'State',
    defaultValue: 13,
    errorText: 'State is required',
    required: true,
    onChange: (e) => _handleChange(e),
    options: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'],
  },
  {
    colSize: '3',
    type: 'text',
    id: 'zip' ,
    name: 'zip',
    label: 'ZIP',
    defaultValue: '60089',
    errorText: 'ZIP is required',
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    type: 'textarea',
    id: 'comments' ,
    name: 'comments',
    label: 'Comments',
    defaultValue: 'Blah blah blah...',
    onChange: (e) => _handleChange(e),
  },
  {
    type: 'checkbox',
    id: 'agree' ,
    name: 'agree',
    label: <span>I agree to the <a href="">Terms &amp; Conditions</a>.</span>,
    errorText: 'Your agreement is required',
    defaultChecked: true,
    required: true,
    onChange: (e) => _handleChange(e),
  },
  {
    type: 'submit',
    text: 'Submit',
    onClick: () => { console.log('Form Submitted!') }
  },
];

class Fieldset extends Component {
  constructor (props) {
    super(props);

    this.state = { fieldset: [] };

    this.formFields = [];
  }

  static propTypes = {
    fields: PropTypes.array.isRequired,
    legend: PropTypes.string, 
    breakpoint: PropTypes.string,
    className: PropTypes.string, 
  };

  static defaultProps = {
    fields: [],
    legend: '',
    className: '',
  };

  componentDidMount () {
    this.setState({ fieldset: this._renderForm() });
  }

  _createGridColumn = (element, colSize) => {
    const { breakpoint } = this.props;
    const breakpointPostfix = breakpoint ? `@${breakpoint}` : '';
    const gridColClass = colSize ?  `l-grid__col--${colSize}${breakpointPostfix}` : '';

    return (
      <div key={ `col-${Fieldset.createUniqueKey()}` }
            className={ `l-grid__col ${gridColClass}` }>{ element }</div>
    );
  };

  _mapToFormModel = (props) => {
    let { formFields, _createGridColumn } = this;
    const colSize = props.colSize || null;
    const hasError = props.hasError ? 'has-error' : '';
    const attrs = _.omit(props, ['label','className','colSize','options']);
  
    switch (props.type) {
      case 'text':
      case 'number':
        formFields.push(
          _createGridColumn(
            <div className="form-item">
              <label>{ props.label }</label>
              <input className={ `${props.className} ${hasError}` } { ...attrs } />
              <div className="error-text">{ props.errorText }</div>
            </div>
            , colSize)
        );
        break;
      case 'textarea':
        formFields.push(
          _createGridColumn(
            <div className="form-item">
              <label>{ props.label }</label>
              <textarea className={ `${props.className} ${hasError}` } { ...attrs }>
                  { props.value }
              </textarea>
              <div className="error-text">{ props.errorText }</div>
            </div>
            , colSize)
        );
        break;
      case 'select':
        formFields.push(
          _createGridColumn(
            <div className="form-item">
              <label>{ props.label }</label>
              <select 
                className={ `${props.className} ${hasError}` }
                onChange={ props.onChange }>
                <option value="">Select State</option>
                { _.map(props.options, (option, i) => {
                  return <option 
                           className={ hasError }
                           key={ `option-${Fieldset.createUniqueKey()}` } 
                           value={ i }
                           selected={ i === props.defaultValue }>{ option }</option>
                }) }
              </select>
              <div className="error-text">{ props.errorText }</div>
            </div>
            , colSize)
        );
        break;
      case 'checkbox':
      case 'radio':
        formFields.push(
          _createGridColumn(
            <div className="form-item">
              <input 
                className={ `${props.className} ${hasError}` } 
                key={ `col-${Fieldset.createUniqueKey()}` } 
                { ...attrs } />
              <label>{ props.label }</label>
              <div className="error-text">{ props.errorText }</div>
            </div>
          , colSize ));
        break;
      case 'submit':
      case 'button':
      case 'reset':
        formFields.push(_createGridColumn(
          <button type={ props.type } onClick={ props.onClick }>{ props.text }</button>
        ), colSize);
        break;
    }
  };

  _renderForm = () => {
    const { fields, isHidden, className, breakpoint, _form, ...other } = this.props;
    const { _mapToFormModel, formFields } = this;

    fields.forEach(field => _mapToFormModel(field));

    return (
      <div className={ `l-grid ${className}` } { ...other }>{ formFields }</div>
    );
  };

  render () {
    const { legend } = this.props;
    const { fieldset } = this.state;

    return (
      <fieldset>
        { legend ? <legend>{ legend }</legend> : null }
        { fieldset }
      </fieldset>
    );
  }

  static createUniqueKey () {
    return Math.round(Math.random() * 100000);
  }
}

class App extends Component {
  _handleChange = e => {
    console.log(e.target.value);
  };
  
  render () {
    
    const { _handleChange } = this;
    
    return (
      <div className="page">
        <form className="form">
          <Fieldset 
            fields={ personalInfoFields } 
            legend="Personal Information"
            breakpoint="medium" />
        </form>  
      </div>
    );
  }
}

render(<App />, document.body);
            
          
!
999px
Loading ..................

Console