Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
The simplest triangle bubble
Implementation idea:
Use ::before and ::after to set the border on both sides. The final border will look like a triangle. One triangle will have the same div color and the other will be white to cover the top.
code
.bubble-box {
position: relative;
border: 2px solid #409eff;
border-radius: 5px;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
}
.bubble-box::before {
position: absolute;
right: 100%;
top: 50%;
margin: -5px 0 0px;
border: 10px solid transparent;
border-right-color: #409eff;
content: "";
}
.bubble-box::after {
position: absolute;
right: 100%;
top: 50%;
margin-top: -3px;
border: 8px solid transparent;
border-right-color: #fff;
content: "";
}
Copy the code
Oblique triangular bubble
Implementation logic
Again use ::after, and use it to make a right triangle
Then use transform to tilt the Angle to achieve the effect.
.bubble-box {
position: relative;
border: 2px solid #409eff;
border-radius: 5px;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
}
.bubble-box::after {
content: "";
position: absolute;
border:10px solid transparent;
border-top-color: #409eff;
border-right-color: #409eff;
right: 100%;
top: 10%;
transform: skewY(10deg);
}
Copy the code
Drag exhaust gas bubble
Implementation approach
Take a closer look at the image: First of all, you can see that the trailing tail in the lower right corner has a curve. The easiest way to achieve a curve in CSS is:
This is to operate on the rounded corners of an element. You only need to operate on both edges at the same time to have an effect.
border-bottom-left-radius: 15px 15px;
Then, the tail is relatively small, not as big as the picture. In this case, the easiest way is to add a layer of white div to cover part of it.
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width.initial-scale=1.0" />
<title>Document</title>
<style>
.bubble-box {
position: relative;
text-align: center;
width: 200px;
height: 50px;
line-height: 50px;
background-color: #409eff;
border-radius: 25px;
}
.bubble-box::before {
content: "";
position: absolute;
z-index: -1;
bottom: -2px;
right: -8px;
height: 20px;
border-right: 20px solid #409eff;
border-bottom-left-radius: 15px 15px;
-webkit-transform: translate(0, -2px);
}
.bubble-box::after {
content: "";
position: absolute;
z-index: 1;
bottom: -2px;
right: -56px;
width: 26px;
height: 20px;
background: white;
border-bottom-left-radius: 10px;
-webkit-transform: translate(-30px, -2px);
}
</style>
</head>
<body style="padding: 100px"> bubble-box">picker Copy the code
Cover the code
Here is a simple code, the general idea is to have, I hope you can improve their own.
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width.initial-scale=1.0" />
<title>Document</title>
<style>
.bubble-box {
position: relative;
border: 2px solid #409eff;
border-radius: 5px;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
}
.bubble-box::before {
position: absolute;
right: 100%;
top: 50%;
margin: -5px 0 0px;
border: 10px solid transparent;
border-right-color: #409eff;
content: "";
}
.bubble-box::after {
position: absolute;
right: 100%;
top: 50%;
margin-top: -3px;
border: 8px solid transparent;
border-right-color: #fff;
content: "";
}
.bubble-child {
margin-top: 10px;
position: relative;
width: 40px;
height: 35px;
border-radius: 50%;
background-color: #409eff;
animation: zy 2.5 s 0.15 s linear infinite;
transform-origin: 20px 35px;
}
.bubble-child::before {
position: absolute;
right: 28%;
top: 90%;
border: 10px solid transparent;
border-top-color: #409eff;
content: "";
}
@-webkit-keyframes zy {
10% {
transform: rotate(45deg);
}
20% {
transform: rotate(-30deg);
}
30% {
transform: rotate(-20deg);
}
40% {
transform: rotate(10deg);
}
50%.100% {
transform: rotate(0deg);
}
}
</style>
</head>
<body style="padding: 100px"> bubble-box"> bubble-child"> picker Copy the code