简体   繁体   中英

how to draw a chat bubbles use Pure CSS

I find to more sample to draw chat bubbles use CSS, but I can't find how to draw this bubbles, I have no idea about the angle of top

在此处输入图片说明


first, thanks, all advice in these question, I have a mistake for not upload my codes that I tried.

finally, thanks, @holden answer that is correct, and I upload my codes after I got the idea how to use a triangle with :after, If anyone has the same problem, I think it can give you some idea :)


if you want to edit my final code, you can go to the online editor ( https://jsfiddle.net/ypgou3wy/ )

 /* layout */ body { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); } .logo { display: inline-block; } /* main */ @mixin tringleWithInCircule() { position: absolute; top: -22px; left: 14px; width: 0; height: 0; border-style: solid; border-width: 0 0 37px 43px; border-top-right-radius: 5px; border-color: transparent transparent blue transparent; } .logo { width: 100px; height: 100px; border-radius: 100%; background: blue; position: relative; } .logo1:after { content: ''; position: absolute; top: -22px; left: 14px; width: 0; height: 0; border-style: solid; border-width: 0 0 37px 43px; border-top-right-radius: 5px; border-color: transparent transparent blue transparent; } .logo2 { transform: scaleY(-1); } .logo2:after { content: ''; position: absolute; top: -22px; left: 14px; width: 0; height: 0; border-style: solid; border-width: 0 0 37px 43px; border-top-right-radius: 5px; border-color: transparent transparent blue transparent; } .logo3 { transform: scaleY(-1) scaleX(-1); } .logo3:after { content: ''; position: absolute; top: -22px; left: 14px; width: 0; height: 0; border-style: solid; border-width: 0 0 37px 43px; border-top-right-radius: 5px; border-color: transparent transparent blue transparent; } .logo4 { transform: scaleX(-1); } .logo4:after { content: ''; position: absolute; top: -22px; left: 14px; width: 0; height: 0; border-style: solid; border-width: 0 0 37px 43px; border-top-right-radius: 5px; border-color: transparent transparent blue transparent; }
 <div class="logo logo1"> </div> <div class="logo logo2"> </div> <div class="logo logo3"> </div> <div class="logo logo4"> </div>

Here is a code that is to create Speech bubble. Also you can change the variables and the pointer position here

.speech-bubble {
    position: relative;
    background: #00aabb;
    border-radius: .4em;
}

.speech-bubble:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 0;
    border: 30px solid transparent;
    border-top-color: #00aabb;
    border-bottom: 0;
    border-left: 0;
    margin-left: -15px;
    margin-bottom: -30px;
}

This CSS should get you started, just play around with it:

#speech-bubble {
   width: 120px; 
   height: 80px; 
   background: blue;
   position: absolute;
   -moz-border-radius: 10px; 
   -webkit-border-radius: 10px; 
   border-radius: 10px;
}
#speech-bubble:before {
   content:"";
   position: absolute;
   width: 0;
   height: 0;
   border-top: 3px solid transparent;
   border-right: 26px solid blue;
   border-bottom: 23px solid transparent;
   margin: 13px 0 0 -25px;
}

Here is the JS Bin demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM