html - 如何为多向箭头工具提示添加边框?

标签 html css tooltip

我有 4 个方向的工具提示,箭头作为 :after 伪元素,如下所示: (See JSFiddle)

 <div class="background">
 <div class="tooltip tooltip-right">
     <i>i</i>
     <div><h4>Achtung!</h4>
         <p>Here is the info for section one</p></div> 
 </div>
.tooltip div {
    display:none;
    color:#000;
    border: 3px solid rgba(117, 175, 67, 0.4);
    background:#FFF;
    padding:15px;
    width: 250px;
    z-index: 99;
 }

.tooltip-right div {
    left: 180%;
    top: -80%;
}

.tooltip div:after {
    position:absolute;
    content: "";
    width: 0;
    height: 0;
    border-width: 10px;
    border-style: solid;
    border-color: #FFFFFF transparent transparent transparent;
    bottom:-20px;
}

.tooltip-right div:after {
    left:-20px;
    top:20px;
    border-color: transparent #FFFFFF transparent transparent;;
} 

我正在研究如何使用 :before 伪元素为箭头添加边框,如 demo here 所示。 ,但我不知道如何更改不同元素的箭头方向。任何人都可以提供帮助或提供指向带箭头和边框的多向工具提示演示的链接吗?

最佳答案

基本原则是,一旦您使用 :after 伪元素放置了边框箭头,您就可以使用 :before 将另一个稍小的箭头放在顶部伪元素。

堆叠是通过 z-index 值完成的。

每个箭头都需要使用绝对值(和一些负边距)进行定位,具体取决于它应该位于的位置。

对于带边框的顶部箭头:

HTML

<div class="tooltip top">
  <p>Tooltip Text</p>
</div>

CSS

.tooltip {
  display:inline-block;
  vertical-align:top;
  height:50px;
  line-height:50px; /* as per div height */
  margin:25px;
  border:2px solid grey;
  width:250px;
  text-align:center;
  position:relative; /* positioning context */
}
.tooltip:before,
.tooltip:after { /*applies to all arrows */
  position:absolute;
  content:"";
}

.tooltip:after {
  /* the is going to be the extra border */
  border:12px solid transparent;
}

.tooltip:before {
 /* the is going to be the inside of the arrow */
  border:10px solid transparent; /* less than outside */ 
}

/* Lets do the top arrow first */

.top:after {
  /* positioning */
  left:50%;
  margin-left:-6px; /* 50% of border */
  top:-24px; /* 2x border */
  border-bottom-color:grey; /* as div border */
 }


.top:before {
  /* positioning */
  left:50%;
  margin-left:-5px; /* 50% of border */
  top:-20px; /* 2x border */
  border-bottom-color:white; /* as div background */
  z-index:5; /* put it on top */
}

我已经完成了附件中的箭头 (TRBL)(带有一些小注释)

CODEPEN EXAMPLE

关于html - 如何为多向箭头工具提示添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19516475/

相关文章:

javascript - 背景图像样式在 HTML header 中不起作用

javascript - 当用户滚动页面时删除事件类

javascript - jquery UI 工具提示的自定义背景图片

charts - 删除顶点图表中的 x 轴工具提示

jquery - 在不使用任何插件的情况下自定义默认工具提示

HTML 模板不工作

Javascript 在 Iframe 中设置下拉字段的值

css - UL inside a Div vertically centered | Bootstrap 3.3.7

jquery - 删除了宽度样式,仍然没有改变。查询?

javascript - Backbone 形式:选择字段的样式选项?