Article 7. Form and Article 7 Form

Source: Internet
Author: User

Article 7. Form and Article 7 Form

Bootstrap provides three forms: vertical forms, inline forms, and horizontal forms.

Create a vertical or basic form:

  • · Add to the parent <form> elementRole = "form".
  • · Place tags and controls in a class. Form-groupIn <div>. This is required to obtain the optimal spacing.
  • · Add a class to all text elements <input>, <textarea>, and <select>. Form-control

 

<Form role = "form">

<Div class = "form-group">

<Label for = "name"> name </label>

<Input type = "text" class = "form-control" id = "name"

Placeholder = "enter a name">

</Div>

<Div class = "form-group">

<Label for = "inputfile"> file input </label>

<Input type = "file" id = "inputfile">

<P class = "help-block"> here is an instance of block-level help text. </P>

</Div>

<Div class = "checkbox">

<Label>

<Input type = "checkbox"> check

</Label>

</Div>

<Button type = "submit" class = "btn-default"> submit </button>

</Form>

 

 

 

 

Inline form:

All the elements in the inline form are aligned to the left and labels are side by side. To create an inline form, you must add the class to the form label.

. Form-inline

<Form class = "form-inline" role = "form">

<Div class = "form-group">

<Label class = "sr-only" for = "name"> name </label>

<Input type = "text" class = "form-control" id = "name"

Placeholder = "enter a name">

</Div>

<Div class = "form-group">

<Label class = "sr-only" for = "inputfile"> file input </label>

<Input type = "file" id = "inputfile">

</Div>

<Div class = "checkbox">

<Label>

<Input type = "checkbox"> check

</Label>

</Div>

<Button type = "submit" class = "btn-default"> submit </button>

</Form>

The display effect is as follows:

 

 

Note: by default, the input, select, and textarea values in Bootstrap are 100% in width. When using an inline form, you must set a width on the Form Control.

Horizontal form: Unlike the other two forms, follow these steps to create a horizontal form.

  • Add a class to the parent <form> element. Form-horizontal.
  • Place tags and controls in a class. Form-groupIn <div>.
  • Add class to label. Control-label.

For example:

<Form class = "form-horizontal" role = "form">

<Div class = "form-group">

<Label for = "firstname" class = "col-sm-2 control-label"> name </label>

<Div class = "col-sm-10">

<Input type = "text" class = "form-control" id = "firstname"

Placeholder = "enter a name">

</Div>

</Div>

<Div class = "form-group">

<Label for = "lastname" class = "col-sm-2 control-label"> last name </label>

<Div class = "col-sm-10">

<Input type = "text" class = "form-control" id = "lastname"

Placeholder = "Enter the last name">

</Div>

</Div>

<Div class = "form-group">

<Div class = "col-sm-offset-2 col-sm-10">

<Div class = "checkbox">

<Label>

<Input type = "checkbox"> remember me

</Label>

</Div>

</Div>

</Div>

<Div class = "form-group">

<Div class = "col-sm-offset-2 col-sm-10">

<Button type = "submit" class = "btn-default"> log on </button>

</Div>

</Div>

</Form>

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.