Hi,
I’m trying to create some CSS speech bubble with a version with the arrow at the top and one with the arrow at the bottom.
I have the one with the arrow at the bottom working, but I can’t work out how to get the arrow on top.
I have this fiddle:
Also, I have duplicated the HTML of the bottom one, but the second one has a 1px line appearing under the arrow.
Can anyone help me create the version with it at the top?
Many thanks
Ray.H
June 25, 2019, 4:10pm
2
To get the arrow at the top just swap out your border-width values
from…
border-width: 20px 20px 0;
to…
border-width: 0 20px 20px;
.bubble-top:before {
content: "";
position: absolute;
top: -20px;
left: 50%;
border-width: 0 20px 20px;
border-style: solid;
border-color: #dc555a transparent;
display: block;
width: 0;}
1 Like
Thank you, that worked great!
1 Like
Hi again,
I’ve noticed that the arrow is not quite centered. I’ve used left: 50% which I thought would center it, but it’s not.
Any ideas how I should center it?
Ray.H
June 25, 2019, 4:52pm
5
Try using calc()
to account for half the 20px width
left: calc(50% - 10px);
1 Like
SamA74
June 25, 2019, 5:01pm
7
I came up with the same, but it needed 20px
subtracting to get the center.
Another way without calc()
was the make tha pseudo element display: inline-block
then align the parent to the centre.
Though doing that to the bubble class will make the text in the bubble centred too. You would probably need an extra container if you don’t want the text in the centre.
1 Like
Ray.H
June 25, 2019, 5:08pm
8
Yep, that would be right since it 's positioning from the left edge
Ray.H
June 25, 2019, 5:20pm
9
And yet another way to do it without calc, while keeping it absolute positioned (with a width) is with auto margins.
left:0;
right:0;
margin:auto;
2 Likes
SamA74
June 25, 2019, 5:58pm
10
I think you nailed it with that one, no calc, no extra mark up.
system
Closed
September 25, 2019, 12:58am
11
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.