How to implement a floating box on the right side in bootstrap

WBOY
Release: 2022-05-06 11:34:22
Original
3154 people have browsed it

In bootstrap, you can use the popover plug-in to realize the floating box on the right side. This plug-in is used to provide an extended view. You can set the display direction of the floating box by setting the "data-placement" attribute in the element. The syntax is: "".

How to implement a floating box on the right side in bootstrap

The operating environment of this tutorial: Windows 10 system, bootstrap version 3.3.7, DELL G3 computer

How to implement the right floating box in bootstrap

Bootstrap pop-up box (Popover) plug-in

The pop-up box (Popover) is similar to the tool tip (Tooltip), providing an expanded view. To activate the popover, users simply hover over the element. The content of the popup box can be filled entirely using the Bootstrap Data API. This method relies on tooltips.

Usage

The popover plug-in generates content and markup according to requirements. By default, popovers are placed behind their triggering elements. You can add a popover in two ways:

  • Through the data attribute: To add a popover, just add data to an anchor/button tag -toggle="popover" will do. The title of the anchor is the text of the popover. By default, the plugin places the popover at the top.

<a href="#" data-toggle="popover" title="Example popover">
    请悬停在我的上面
</a>
Copy after login
  • Via JavaScript: Enable popover via JavaScript:

$(&#39;#identifier&#39;).popover(options)
Copy after login

Popover plugin Unlike the drop-down menus and other plugins discussed previously, it is not a pure CSS plugin. To use the plugin, you must activate it using jquery (read javascript). Use the following script to enable all popovers on the page:

$(function () { $("[data-toggle=&#39;popover&#39;]").popover(); });
Copy after login

The following example demonstrates the use of the popover plug-in through the data attribute.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Bootstrap 实例 - 弹出框(Popover)插件</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="padding: 100px 50px 10px;" >
<button type="button" class="btn btn-warning" title="Popover title"  
data-container="body" data-toggle="popover" data-placement="right" 
data-content="右侧的 Popover 中的一些内容">
右侧的 Popover
</button>
</div>
<script>
$(function () { 
$("[data-toggle=&#39;popover&#39;]").popover();
});
</script>
</body>
</html>
Copy after login

Output result:

How to implement a floating box on the right side in bootstrap

Related recommendations: bootstrap tutorial

The above is the detailed content of How to implement a floating box on the right side in bootstrap. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template