4

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?

Harry
  • 87,580
  • 25
  • 202
  • 214
Luca
  • 385
  • 3
  • 15
  • possible duplicate of [How to create a clickable div with a triangle on the side / speech bubble / message box with arrow / tail / triangle](http://stackoverflow.com/questions/30299093/how-to-create-a-clickable-div-with-a-triangle-on-the-side-speech-bubble-mess) – jbutler483 May 20 '15 at 08:36

2 Answers2

6

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>
Harry
  • 87,580
  • 25
  • 202
  • 214
4

I'd suggest you to use svg.

body {
  background: rgb(83, 110, 218)
}
<svg width="300" height="60" viewBox="0 0 300 60">
  <path d="M20 5h270v50h-270v-12.5l-10 -12.5l10 -12.5z" fill="white" />
  <path d="M16 1h278v58h-278v-15l-11 -14 l11,-14z" fill="none" stroke-width="2.5" stroke="white" />
  <text x="150" y="35" text-anchor="middle">Hello World</text>
</svg>
Weafs.py
  • 22,731
  • 9
  • 56
  • 78
  • As much as your answer is also a suitable answer, my solution needs to work on IE8 and SVG's don't work on IE8. Thanks anyways!! – Luca Jan 26 '15 at 14:05
  • 1
    IE8 doesnt support box-shadows, so i have no idea how harry's answer(though very nice) started working for you in IE8. BTW you can get IE8 support by using Raphael. – Max Payne May 19 '15 at 04:10