CSS轮廓和侧面有三角形的边框

Luc*_*uca 3 html css css3 css-shapes

我正在尝试创建一个带有三角形的双边界工具提示,但我无法弄清楚如何做轮廓部分,因为没有轮廓 - 右/左/上/下.

这是我到目前为止所拥有的

body {
  background-color: rgb(83, 110, 218);
}
.trigger {
  margin-top: 150px;
  position: relative;
  width: 30px;
  height: 30px;
  background-color: #000;
}
.tooltip {
  /* Misc */
  text-align: center;
  padding-top: 20px;
  background-color: white;
  position: absolute;
  width: 300px;
  height: 50px;
  left: 70px;
  top: -25px;
  outline-color: white;
  outline-width: 3px;
  outline-style: solid;
  border-color: rgb(83, 110, 218);
  border-width: 3px;
  border-style: solid;
}
.tooltip:after,
.tooltip:before {
  right: 100%;
  top: 50%;
  border: solid transparent;
  content: " ";
  position: absolute;
  pointer-events: none;
}
.tooltip:after {
  border-color: rgba(136, 183, 213, 0);
  border-right-color: white;
  border-width: 20px;
  margin-top: -20px;
}
.tooltip:before {
  border-color: rgba(194, 225, 245, 0);
  border-right-color: rgb(83, 110, 218);
  border-width: 26px;
  margin-top: -26px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="trigger">
  <div class="tooltip">
    Hello World
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

或者去这里:小提琴

有人知道怎么做到这一点吗?

Har*_*rry 6

对于纯CSS替代,您可以使用下面的代码段.它基本上使用a double作为border-style主矩形(而不是outline)和一个旋转45度的伪元素来产生三角形.三角形border的颜色与主矩形(或主体)的内边框颜色相同,颜色为box-shadow白色以产生双边框效果.伪元素被适当地定位以使其看起来好像它是border主矩形的延续.

注意:要修改边框的粗细,必须相应地修改border-widthborder-width元素,伪元素的父元素,box-shadow伪元素的元素和伪元素的位置.

body {
  background-color: rgb(83, 110, 218);
}
.trigger {
  margin-top: 150px;
  position: relative;
  width: 30px;
  height: 30px;
  background-color: #000;
}
.tooltip {
  /* Misc */
  text-align: center;
  padding-top: 20px;
  background-color: white;
  position: absolute;
  width: 300px;
  height: 50px;
  left: 70px;
  top: -25px;
  border-color: rgb(83, 110, 218);
  border-width: 6px;
  border-style: double;
}
.tooltip:before {
  left: -11.75px;
  top: 35%;
  height: 20px;
  width: 20px;
  border: 2.5px solid rgb(83, 110, 218);
  box-shadow: -2px 2px 0px 0px white;
  border-right: none;
  border-top: none;
  content: " ";
  background: white;
  position: absolute;
  pointer-events: none;
  transform: rotate(45deg);
}
Run Code Online (Sandbox Code Playgroud)
<div class="trigger">
  <div class="tooltip">
    Hello World
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)