如何制作工具提示,带有边框的左箭头

时间:2019-04-17 10:43:13

标签: javascript jquery html css bootstrap-4

我要创建一个工具提示,单击工具提示图标后会显示内容。 目前,它正在悬停,但我希望在单击时使用移动响应。

台式机设计应类似于: enter image description here

移动设计应如下所示:

enter image description here

还有其他方法可以执行此操作...用我的代码还是其他方法。

.tooltip-inner{
  max-width: 527px;
  /* width: 600px;  */
    padding:10px 15px;
    color:#212121;
    text-align:center;
    background: #fff;
    font-size: 16px;
    line-height: 23px;
    font-family: Arial;
    border: 2px solid #D6D6D6;
    -webkit-border-radius:9px;
    -moz-border-radius:9px;
    border-radius:6px;
    text-align: left;
    position: relative;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::before, .tooltip.bs-tooltip-right .arrow::before,
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::after, .tooltip.bs-tooltip-right .arrow::after {
  right: 100%;
	top: 50%;
	border: solid transparent;
	content: " ";
	height: 0;
	width: 0;
	position: absolute;
	pointer-events: none;
  margin-left: -50px;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::after, .tooltip.bs-tooltip-right .arrow::after {
  border-color: rgba(136, 183, 213, 0);
	border-right-color: #fff;
	border-width: 15px;
	margin-top: -15px;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::before, .tooltip.bs-tooltip-right .arrow::before {
  border-color: rgba(214, 214, 214, 0);
	border-right-color: #D6D6D6;
	border-width: 18px;
	margin-top: -18px;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <a style="position:relative;" class="text-dark" data-toggle="tooltip" data-html="true" data-placement="right" title="The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.">
     Hover here
    </a>

<h1>Dummy text</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>


    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <script>
      $(function () {
        $('[data-toggle="tooltip"]').tooltip()
      })
  </script>
  </body>
</html>

3 个答案:

答案 0 :(得分:0)

  1. 首先,您必须查找设备是在移动设备中还是在台式机中。

$(window).resize(function(){
    var tooltipPosition = ($(window).width < 768) ? 'left' : 'right';
    $('[data-toggle="tooltip"]').tooltip('placement': tooltipPosition)
    });

答案 1 :(得分:0)

在标签中添加数据触发以设置触发事件。 Bootstrap是一个响应式框架。因此您无需担心屏幕。 :)

Check this for more data-options

.tooltip-inner{
  max-width: 527px;
  /* width: 600px;  */
    padding:10px 15px;
    color:#212121;
    text-align:center;
    background: #fff;
    font-size: 16px;
    line-height: 23px;
    font-family: Arial;
    border: 2px solid #D6D6D6;
    -webkit-border-radius:9px;
    -moz-border-radius:9px;
    border-radius:6px;
    text-align: left;
    position: relative;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::before, .tooltip.bs-tooltip-right .arrow::before,
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::after, .tooltip.bs-tooltip-right .arrow::after {
  right: 100%;
	top: 50%;
	border: solid transparent;
	content: " ";
	height: 0;
	width: 0;
	position: absolute;
	pointer-events: none;
  margin-left: -50px;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::after, .tooltip.bs-tooltip-right .arrow::after {
  border-color: rgba(136, 183, 213, 0);
	border-right-color: #fff;
	border-width: 15px;
	margin-top: -15px;
}
.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::before, .tooltip.bs-tooltip-right .arrow::before {
  border-color: rgba(214, 214, 214, 0);
	border-right-color: #D6D6D6;
	border-width: 18px;
	margin-top: -18px;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <a style="position:relative;" class="text-dark" data-trigger="click" data-toggle="tooltip" data-html="true" data-placement="right" title="The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.">
     click to show tooltip
    </a>

<h1>Dummy text</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>


    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <script>
      $(function () {
        $('[data-toggle="tooltip"]').tooltip()
      })
  </script>
  </body>
</html>

答案 2 :(得分:0)

将弹出框用于这种样式。

audio
$(function () {
        $('[data-toggle="popover"]').popover()
      })
.bs-popover-right, .bs-popover-left{
  max-width: 527px;
    padding:10px 15px;
    color:#212121;
    background: #fff;
    font-size: 16px;
    line-height: 23px;
    font-family: Arial;
    border: 2px solid #D6D6D6;
    -webkit-border-radius:9px;
    -moz-border-radius:9px;
    border-radius:6px;
}
.popover-tip {
  width: 40px;
  height: 40px;
}
.popover-tip:focus {
  outline: 0;
}