Learn 'Mobile First' Web Design Using Bootstrap 3 by Rahul A. Sakla - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Chapter 5 Forms

5.1 Default Form

lndividual form controls automatically receive some global styling. All textual <input>, <textarea>, and <select> elements with.form-control are set to width: 100%; by default. Wrap labels and controls in .form-group for optimum spacing.

 

img75.png

 

img76.png

img77.png

img78.png

img79.png

img80.png

 

img4.pngDo not mix form groups directly with input groups. Instead, nest the input   group inside of the form group.

 

5.2 Inline Form

Add .form-inline to your form (which doesn't have to be a <form>) for left- aligned and inline-block controls. This only applies to forms within viewports that are at least 768px wide.

img4.pngInputs and selects have width: 100%; applied by default in Bootstrap. Within   inline forms, we reset that to width: auto; so multiple controls can reside on the same line. Depending on your layout, additional custom widths may be required.

img81.png

 

img82.png

img83.png

 

5.3 Horizontal Form

 

Use Bootstrap's predefined grid classes to align labels and groups of form controls in a horizontal layout by adding .form-horizontal to the form (which doesn't have to be a <form>). Doing so changes .form-group s to behave as grid rows, so no need for .row.

img84.png

 

img85.png

img86.png

img87.png

 

5.4 Supported Controls

Examples of standard form controls supported in an example form layout.

Inputs

Most common form control, text-based input fields. Includes support for all HTMLS types: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, and color.

Inputs will only be fully styled if their type is properly declared.

 

5.5 Focus State

Bootstrap remove the default outline styles on some form controls and apply a box-shadow in its place for :focus

img88.png

 

5.6 Disabled State

Add the disabled boolean attribute on an input to prevent user input and trigger a slightly different look.

img89.png

img90.png

 

5.7 Readonly State

Add the readonly boolean attribute on an input to prevent user input and style the input as disabled.

img91.png

img92.png

 

5.8 Validation States

Bootstrap includes validation styles for error, warning, and success states on form controls. To use, add .has-warning, .has-error, or .has-success to the parent element. Any .control-label, .form-control, and .help-block within that element will receive the validation styles.

img93.png

img94.png

img95.png

img96.png

img97.png

img98.png

img99.png

img100.png

 

5.9 With Optional Icons

You can also add optional feedback icons with the addition of .has-feedback and the right icon.

Icons, labels, and input groups