CSSで吹き出しを作る
LPなどで吹き出しを付けたいときのために、簡単に作成する方法をご紹介致します。
まずは、吹き出しの中身を下記のように作成致します。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="fukidashi-block">
<p class="sentence">吹き出し</p>
</div>
</body>
</html>
<style>
.fukidashi-block {
text-align: center;
background-color: green;
padding: 10px 16px;
position: relative;
border-radius: 10px;
color: white;
font-weight: 700;
}
</style>
次に、吹き出しで一番難しく感じる三角形部分。cssにコードを追加します。
これで完成です。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="fukidashi-block">
<p class="sentence">吹き出し</p>
</div>
</body>
</html>
<style>
/* 追加 */
.sentence::before {
position: absolute;
content: "";
border: 9px solid transparent;
border-top: 11px solid green;
bottom: -40%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
}
/* ここまで */
.fukidashi-block {
text-align: center;
background-color: green;
padding: 10px 16px;
position: relative;
border-radius: 10px;
color: white;
font-weight: 700;
}
</style>
以上になります。