Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS outline & border with triangle on side

I'm trying to create a double bordered tool tip with a triangle but I can't figure out how to do the outline part because there is no outline-right/left/top/bottom.

Here is what I have so far

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;
}
<div class="trigger">
  <div class="tooltip">
    Hello World
  </div>
</div>

Or go here: Fiddle

Does anybody know how to accomplish this?

like image 602
Luca Avatar asked Sep 12 '25 21:09

Luca


1 Answers

For a pure CSS alternate, you can use the below snippet. It basically uses a double for the border-style of the main rectangle (instead of outline) and a pseudo-element which is rotated by 45 degrees to produce the triangle. The triangle has a border which is the same color as the inner border of the main rectangle (or the body) and a box-shadow which is white in color to produce the double border effect. The pseudo-element is positioned appropriately to make it look as though it is a continuation of the border of the main rectangle.

Note: To modify the thickness of the border, the border-width of parent, border-width of the pseudo-element, the box-shadow on the pseudo-element and the positioning of the pseudo-element should be modified accordingly.

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);
}
<div class="trigger">
  <div class="tooltip">
    Hello World
  </div>
</div>
like image 163
Harry Avatar answered Sep 15 '25 11:09

Harry