I have started an article series on Bootstrap and published six articles so far. Read the previous six parts here,
Introduction
In this article we will create Bootstrap Panels with different styles. Bootstrap panel components are useful when sometimes we want to put content in a box on the webpages.
Panels
A panel in bootstrap is a bordered box with some padding around its content. To create a basic panel,we use .panel class to the <div> element, and content inside the panel has a .panel-body class.
Example 1 : Creating Panel
In this example we will create a basic panel by using .panel class to the <div> element and we will write content in the panel by using .panel-body class to the <div> element. In this example we will use .panel-default class for styling of the panel by writing the following code.
- <!DOCTYPE html>
-
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Bootstrap Part7</title>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Bootstrap Panel</h2>
- <div class="panel panel-default">
- <div class="panel-body">Demo Panel</div>
- </div>
- </div>
- <script src="js/jquery-2.1.4.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </body>
- </html>
Output
Panel Heading
We can add a heading to our panel by using
.panel-heading class.
Example 2: Creating Panel with Heading
In this example we will add
.panel-heading class for creating Heading of the panel by writing the following code.
- <!DOCTYPE html>
-
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Bootstrap Part7</title>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Bootstrap Panel With Heading</h2>
- <div class="panel panel-default">
- <div class="panel-heading">Panel Heading</div>
- <div class="panel-body">Panel Body:Content Write Here...</div>
- </div>
- </div>
- <script src="js/jquery-2.1.4.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </body>
- </html>
Output
Panel Heading With Title
We can use heading elements from <h1> to <h6> with a
.panel-title class.
Example 3: Panel Title
In this example we will use
.panel-title class for creating Panel Title by writing following code.
- <!DOCTYPE html>
-
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Bootstrap Part7</title>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Bootstrap Panel Heading With Title</h2>
- <div class="panel panel-default">
- <div class="panel-heading">
- <h1 class="panel-title">Panel Title</h1>
- </div>
- <div class="panel-body">Panel Body:Content Will Be Here...</div>
- </div>
- </div>
- <script src="js/jquery-2.1.4.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </body>
- </html>
Output
Panel Footer
We can add a footer to our panels by using the
.panel-footer class. In footer we can add text, links, buttons etc.
Example 4: Panel with Footer
In this example we will create footer of the panel by using
.panel-footer class by writing the following code.
- <!DOCTYPE html>
-
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Bootstrap Part7</title>
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <h2>Bootstrap Panel Footer</h2>
- <div class="panel panel-default">
- <div class="panel-body">Panel Body:Content Will Be Here...</div>
- <div class="panel-footer">Panel Footer</div>
- </div>
- </div>
- <script src="js/jquery-2.1.4.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </body>
- </html>