Bootstrap 4 Popover

Bootstrap 4 Popover

Popover

A popover is similar to the tooltip. The only difference between tooltip and Popover is that in the tooltip, the popup box appears when you move the cursor over the element or link. In the Popover, the popup box appears when you click on the element. The Popover also contains more content than the tooltip.

Steps for creating Popover

  • Add the data-toggle=”popover” attribute to the <a> element.
  • Add the title attribute to the <a> to add the title or header in the popup box.
  • Add the data-content attribute to the <a>, which is used to add content such as paragraph, sentence, etc. to the popup box.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Popover Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> 

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> 

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"> </script> 

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"> </script> 

</head>

<body>

<div class="container">

  <h3>Popover</h3>

  <a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</a>

</div>

<script>

$(document).ready(function(){

  $('[data-toggle="popover"]').popover(); 

});

</script>

</body>

</html>

Output

Bootstrap 4 Popover

Positioning Popovers – The default position of the popover is the right side of the element. You can set the position of the popover on your own to the left, right, top, and bottom with the help of data-placement attribute.

  • To set the position of the popover to the left, add the data-placement=”left” attribute.
  • To set the position of the popover to the right, add the data-placement=”right” attribute.
  • To set the position of the popover at the top, add the data-placement=”top” attribute.
  • To set the position of the popover at the bottom, add the data-placement=”bottom” attribute.

Note: Sometimes the popover will not work properly because of small space. If you set the data-placement value “top” and there is no proper space for the popover on the top of the element then the popover will appear on the bottom of the element.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Popover Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> 

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> 

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"> </script> 

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"> </script> 

</head>

<body>

<div class="container">

  <h3>Popover</h3>

  <a href="#" title="Header" data-toggle="popover" data-placement="top" data-content="Content">Top</a>

  <a href="#" title="Header" data-toggle="popover" data-placement="bottom" data-content="Content">Bottom</a>

  <a href="#" title="Header" data-toggle="popover" data-placement="left" data-content="Content">Left</a>

  <a href="#" title="Header" data-toggle="popover" data-placement="right" data-content="Content">Right</a>

</div>

<script>

$(document).ready(function(){

  $('[data-toggle="popover"]').popover(); 

});

</script>


</body>

</html>

Output

Bootstrap 4 Popover

Closing Popover – The popover disappears when you click on the element. Add the data-trigger=”focus” attribute, this feature allows you to click anywhere on the screen to make the popover disappear and also enhance the user experience.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Popover Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> 

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> 

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"> </script> 

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"> </script> 

</head>

<body>

<div class="container">

  <h3>Popover</h3>

  <p> Click anywhere on the screen to make the <strong>popover</strong> disappear</p>

    <a href="#" title="Dismissible popover" data-toggle="popover" data-trigger="focus" data-content="Click anywhere in the document to close this popover">Click me</a>

</div>

<script>

$(document).ready(function(){

  $('[data-toggle="popover"]').popover(); 

});

</script

</body>

</html> 

Output

Bootstrap 4 Popover

Note: You can also make you popover visible when you move cursor over the element. For this, add the data-trigger=”hover” attribute to the <a> element.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Popover Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> 

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> 

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"> </script> 

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"> </script> 


</head>

<body>

<div class="container">

  <h3>Popover</h3>

  <a href="#" title="Header" data-toggle="popover" data-content="Some content">Click Me</a><br>

  <a href="#" title="Header" data-toggle="popover" data-trigger="hover" data-content="Some content">Hover over me</a>

</div>

<script>

$(document).ready(function(){

  $('[data-toggle="popover"]').popover(); 

});

</script>

</body>

</html>

Output

Bootstrap 4 Popover

Related Topics

Bootstrap 4 Utilities

Bootstrap 4 Utilities Bootstrap 4 utilities also known as helper classes that are used to add more style to the components. Utilities are used to make the website or webpage more stylish or elegant....

10 minutes read.

Bootstrap 4 Filters

 Bootstrap 4 Filters Bootstrap 4 provides a filter component that is used to search an element from a list, table, etc. Bootstrap does not contain any component or utility that helps...

5 minutes read.

Bootstrap 4 Toast

Bootstrap 4 Toast Bootstrap 4 offers a Toast component, which is quite similar to the alert box and pushes notifications. The toast is visible on the screen for a few seconds when any...

5 minutes read.

Bootstrap Typography

Bootstrap provides simple and easily customized typography for headings, body text, lists, and many more. Headline <h1> to <h6> By default, Bootstrap has HTML headings (<h1> to <h6>) that are given below: Example <h1>h1. Bootstrap heading</h1>   <h2>h2. Bootstrap heading</h2>   <h3>h3. Bootstrap heading</h3>   <h4>h4. Bootstrap heading</h4>   <h5>h5. Bootstrap heading</h5>   <h6>h6. Bootstrap heading</h6> Try Now ←...

1 minute read.

Bootstrap With CSS

← Prev Next → ...

1 minute read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid Systems Bootstrap offers a responsive and mobile-first grid system with the help of which we can divide the screen of the web browser into 12 horizontal parts. It has predefined classes...

4 minutes read.

Bootstrap 4 Card

In Bootstrap 4, a card is a bordered box with padding around its content. It has options for headers, footers, colors, content, etc. The card provides the link, title, image,...

8 minutes read.

Bootstrap 4 Popover

Bootstrap 4 Popover Popover A popover is similar to the tooltip. The only difference between tooltip and Popover is that in the tooltip, the popup box appears when you move the cursor...

6 minutes read.

Bootstrap 4 Modal

Bootstrap 4 Modal The Modal is a component of Bootstrap 4, which is a dialog box or pop-up window. The modals are used to provide information or warning to the user, such as...

18 minutes read.

Bootstrap 4 Pagination

Bootstrap 4 Pagination Bootstrap pagination is used to show the existence of a series of web pages of the website. It allows navigation on multiple pages of a website. In pagination, there is a block...

9 minutes read.

Bootstrap Glyphicons

Bootstrap Glyphicon is used to create different type of glyphicons It is used in the web project. It provides 260 Glyphicons from the Glyphivons Halflings set. There are various examples of...

1 minute read.

Dropdown & Dropup

Bootstrap Dropdowns The bootstrap dropdown menu is used to create a toggleable menu. It provides users to choose one value from a predefined list. Before creating dropdown menu, we have to know...

3 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Bootstrap First Example

1) Add HTML5 doctype Before starting the example of Bootstrap, we should know about the some basic rules of Bootstrap. We have to add HTML5 doctype with lang element and CSS properties. <!DOCTYPE html>   <html lang="en">     <head>       <meta charset="utf-8">      </head>   </html> 2) Bootstrap...

2 minutes read.

CakePHP Layouts & Elements

A layout includes a presentation code that can be wrapped out in your view. It means that what you want to see in your view should be well-positioned in layout. When you create...

9 minutes read.

Bootstrap Wells

In Bootstrap, well are used to add a rounded border around an element. It is default some padding and gray background color. It is like a container that displays the content....

1 minute read.

Bootstrap 4 Dropdowns

Bootstrap Dropdowns Bootstrap 4 provides a dropdown component, which is a toggle and contextual layout, used to display a predefined list of links. It allows the user to select a value from the dropdown...

15 minutes read.

Bootstrap Input groups

Bootstrap 4 Input groups The input group is a component of Bootstrap 4, which is used to create interactive and stylish form controls. With the help of input groups, you can easily customize the input...

8 minutes read.

Bootstrap Images

Bootstrap 4 Images Bootstrap provides several classes for images to make them responsive and also helps to give some style to the images. Image Shapes Rounded Corners Bootstrap 4 offers .rounded class that makes the corners...

5 minutes read.