Reputation: 385
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?
Upvotes: 4
Views: 3622
Reputation: 22992
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>
Upvotes: 4
Reputation: 89750
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, thebox-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>
Upvotes: 6