Learn how to create a panel using bootstrap and put your content inside the block box. Add heading in the Bootstrap panel in the different formats using the contextual classes. Learn each section given with examples.
Here is a simple example of Bootstrap Panel:-
Create Basic Bootstrap Panel
To create a simple panel using the bootstrap, you have to put all your content inside the <div> element with two class .panel
and .panel-default
. Inside this div, you can add your panel body content using the class .panel-body
.
See the example below to create your own panels.
1 2 3 4 5 |
<div class="panel panel-default"> <div class="panel-body"> This is the simple panel content inside the panel box. </div> </div> |
Output
Bootstrap Panel with Heading
You can add heading inside the panels with the content body as given in the above example. To add a heading, you have to use the class .panel-heading
as the class of the heading inside the panels.
In the below example, there is a heading and the body content inside the panels.
1 2 3 4 5 6 |
<div class="panel panel-default"> <div class="panel-heading">Panel Heading</div> <div class="panel-body"> This is the simple panel content inside the panel body. </div> </div> |
Output
You can also add the title of the panel using the class .panel-title
in the class .panel-heading
.
1 2 3 4 5 6 7 8 |
<div class="panel panel-default"> <div class="panel-heading"> <span class="panel-title">Panel Title</span> </div> <div class="panel-body"> This is the simple panel content inside the panel body. </div> </div> |
Output
Panel With Footer
In addition to the headings and body content, you can also add panel footer using the class .panel-footer
. Add the class below the panel body content. The footer display with some light background looking same as the header color.
1 2 3 4 5 6 7 8 |
<div class="panel panel-default"> <div class="panel-body"> This is the simple panel content inside the panel box. </div> <div class="panel-footer"> This is Panel Footer </div> </div> |
Output
Contextual Classes in Bootstrap Panel
Contextual classes are the useful classes to display the panel in different border colors and heading colors. In addition to the default panel, you can use 5 contextual classes given in the table below with the descriptions.
Class Name | Description |
---|---|
.panel-primary |
Use this class to display the primary content using the panels. |
.panel-success |
Specify this class to display the success messages in the panels |
.panel-info |
You can use this class to display the informational messages using the panels |
.panel-warning |
Display warning messages using this class as the class of the panels. |
.panel-danger |
Create an error message box using this class in the panels. |
See each panel with the examples given below for each different types of classes. I have added the default panels in the below example because default panel also contains the look and feel for panels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<div class="panel panel-default"> <div class="panel-heading">default Heading</div> <div class="panel-body"> Default panel content inside the default panel box. </div> </div> <div class="panel panel-primary"> <div class="panel-heading">Primary Heading</div> <div class="panel-body"> Primary panel content inside the primary panel box. </div> </div> <div class="panel panel-success"> <div class="panel-heading">Success Heading</div> <div class="panel-body"> Success panel content inside the success panel box. </div> </div> <div class="panel panel-info"> <div class="panel-heading">Info Heading</div> <div class="panel-body"> Information panel content inside the info panel box. </div> </div> <div class="panel panel-warning"> <div class="panel-heading">Warning Heading</div> <div class="panel-body"> Warning panel content inside the warning panel box. </div> </div> <div class="panel panel-danger"> <div class="panel-heading">Error Heading</div> <div class="panel-body"> Error panel content inside the error panel box. </div> </div> |
Output
Most of all classes are useful in creating different types of messages for your websites.
Table Inside Panel
You can also add tables in the panels by adding it after the body content of the panel. There are a different way of adding a table inside the panels. So, let’s learn each one with the examples given below.
Table inside Panel With Panel Body
If you add the body content of the panel, it will come between the panel heading and the table. Use the class .table
as the class of the table to put it inside the panels. However, you can add any table classes to the panel table content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<div class="panel panel-default"> <div class="panel-heading">This is the panel heading</div> <div class="panel-body"> This is the simple panel content inside the panel box. </div> <table class="table"> <tr> <th>Cricket Name</th> <th>Score</th> </tr> <tr> <td>Murali Vijay</td> <td>87</td> </tr> <tr> <td>Chris Gayle</td> <td>96*</td> </tr> <tr> <td>Andrew Russel</td> <td>187</td> </tr> </table> </div> |
Output
Cricket Name | Score |
---|---|
Murali Vijay | 87 |
Chris Gayle | 96* |
Andrew Russel | 187 |
Table inside Panel Without Panel Body
If you do not add the panel body content in the panels, the table will come just after the panel heading.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<div class="panel panel-default"> <div class="panel-heading">This is the panel heading</div> <table class="table"> <tr> <th>Cricket Name</th> <th>Score</th> </tr> <tr> <td>Murali Vijay</td> <td>87</td> </tr> <tr> <td>Chris Gayle</td> <td>96*</td> </tr> <tr> <td>Andrew Russel</td> <td>187</td> </tr> </table> </div> |
Output
Cricket Name | Score |
---|---|
Murali Vijay | 87 |
Chris Gayle | 96* |
Andrew Russel | 187 |
Add List Group Inside the Bootstrap Panel
Add your list group item inside the panels as given in the example below. The first element of the list group item is active using the class .active
.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<div class="panel panel-default"> <div class="panel-heading">This is the panel heading</div> <div class="panel-body"> This is the simple panel content inside the panel box. </div> <ul class="list-group"> <li class="list-group-item active">Computer</li> <li class="list-group-item">Laptop</li> <li class="list-group-item">Mouse</li> <li class="list-group-item">Printer</li> <li class="list-group-item">Keyboard</li> </ul> </div> |
Output
- Computer
- Laptop
- Mouse
- Printer
- Keyboard