"."/> ".">

Home  >  Article  >  Web Front-end  >  How to implement a floating box on the right side in bootstrap

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

WBOY
WBOYOriginal
2022-05-06 11:34:223106browse

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>
  • Via JavaScript: Enable popover via JavaScript:

$(&#39;#identifier&#39;).popover(options)

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(); });

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>

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!

Statement:
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