Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile-first projects on the web and you can access it at http://getbootstrap.com/ .
Bootstrap has many features that meet the various needs of a web application. It has different CSS classes for each of the HTML elements so that you can use it without touching any CSS code. However, if you wish to override it, you can do so.
Let us look at each of the features of Bootstrap in brief.
The grid system in Bootstrap helps you to create a responsive layout for your application. This feature makes your application look great in all devices of different shapes including mobile devices.
Bootstrap provides a fluid grid system, which scales up to twelve columns as the device or viewport size increases. You can think of grid system as being like columns in an Excel sheet (like the one in the following screenshot):
We can combine multiple columns to create a wider column. In the second row in the preceding screenshot, we have used a single column (using class .col-md-1
) twelve times. In the third row, we are using a CSS class (.col-md-2
) to create six wider columns instead of twelve shorter columns. Likewise, we are creating a lesser number of wider columns.
All form controls receive global styling when you use Bootstrap in your application. The following is one such example (the screenshot is taken from the Bootstrap site):
The following is the code for the preceding form. Related HTML elements are grouped together in the form. For example, the labels for the Email and Email address input text boxes are grouped together. The same is the case for Password and File input.
Inline forms are forms where all the form elements are on the same line (as shown in the following screenshot). We need to add the class form-inline
to the form
element.
In horizontal forms, we have each element group on a separate line; Email label, Email input on a line and Password label, Password input on a line (as shown in the following screenshot):
To apply the horizontal form styling, we just need to add the class form-horizontal
as in the following code. Just like other forms, we need to group the related HTML elements together by applying the CSS class form-group
:
For basic styling, add the base CSS class table
to the table
HTML element as shown in the following screenshot:
In a striped table, the background of alternate rows will be of the same color. In the following screenshot, the background color of the first row and third row are the same color. You can apply the table-striped
class to apply the striped table behavior to the table HTML element.
When you move your mouse over any of the rows in the table, the background color of the row is changed. This hover behavior can be achieved by applying the CSS class table-hover
along with the class table
to the HTML table element.
We can have a bordered table (as in the following screenshot), if we apply the CSS class table-bordered
to the table
element.
There are times when you want to highlight rows based on the data value. For example, if you are showing inventory data in tabular format, you might want to highlight the rows with a red background color for the items whose count is less than the stipulated count. In this case, you can apply a danger
class to table rows to highlight them in a red color. There are different types of contextual class available for highlighting in different colors. You can apply these classes to individual cells instead of the complete rows.
There are different styling options available for making buttons appear in different colors. For all the buttons, the base button class btn
has to be applied:
The btn-primary
button class is used to highlight the button in blue whereas the btn-success
button class highlights the button in green. In the preceding screenshot, different options for styling the button are shown.
Based on the context, you might want to change the color of the text. For example, you might want to make the text appear in green if the previous operation is successful. For an unsuccessful operation, you might want to show the error message in a red. In such scenarios, you might use this helper CSS classes to show them in different colors.
We have seen various features of Bootstrap. Now, let us use Bootstrap to make our application look good. Basically, we have two major components in our view—a form at the top to get the input from the user and a table at the bottom to display the results in a table.