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 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 Tables

We can create different types of responsive and awesome bootstrap table like: striped , border etc. Bootstrap Basic Table We can create a basic bootstrap table by using its class .table. It has...

3 minutes read.

Bootstrap 4 Progress Bar

Bootstrap Progress Bar Bootstrap 4 offers progress bars that are used to represent the progress of tasks such as downloading a file, software installation, etc. on the computer. It represents the percentage of the...

9 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.

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 4 Media Objects

Bootstrap 4 Media Objects Bootstrap 4 offers a media object component that aligns the media objects and the content. The media object is used to create a repetitive and complex component...

7 minutes read.

Bootstrap Validation Example

Validation We can provide valuable and actionable feedback to the users through an HTML form validation. It happens via custom styles or behaviors of default browsers and JavaScript. How does validation work...

4 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 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap Badges and Labels

Bootstrap Badges Bootstrap Badges are numerical indicators. It is used to show that how many items are associated with a link.The .badge class is used to create of Bootstrap Badges. Let us see...

2 minutes read.

Bootstrap 4 Tutorial

What is Bootstrap? Bootstrap is a CSS (Cascading Style Sheets) framework, which is used to develop a responsive website. It is an open-source and mobile-first front-end framework. It has design templates that are based...

4 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid System The bootstrap 4 grid system is used to create a responsive website layout. The bootstrap 4 offers a mobile-first flexbox grid system that allows you to divide...

4 minutes read.

Bootstrap 4 List Groups

Bootstrap 4 List Groups Bootstrap 4 offers List Group component, which is used to display a series of content in an organized way. The most common list group is an unordered...

13 minutes read.

Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each...

5 minutes read.

Bootstrap 4 Jumbotron

Bootstrap 4 Jumbotron Bootstrap offers Jumbotron, which is used to get more attention to specific content or information on the web page. It provides a gray background-color to the content to make that content...

2 minutes read.

Difference between bootstrap.css and bootstrap-theme.css

The "bootstrap.css" uses to create a website with pre-existing designs and context. It uses basic Bootstrap classes like rows and columns with a CSS styling tool. The website is styled...

5 minutes read.

Bootstrap Grid System Example

Bootstrap Grid System Example Stacked to horizontal – In stacked to the horizontal grid system, the grid columns are stacked on top of each other on extra small devices and becomes...

7 minutes read.

Bootstrap List group

Bootstrap list group provides a group of a list of items. The most basic list is an unordered list. We can use <ul> element with .list-group class and <li> element with .lsit-group-item. Let us see...

3 minutes read.