9cubed
ブログ | Tailwind | Vite | Python | MariaDB | Node.js | Linux | PowerShell | Docker | Git | その他 | 将棋ウォーズ | 歌の練習
HTML・CSS・JavaScript

border による吹き出しの作成

公開日:2020-10-24
更新日:2020-10-24

1. 概要

border を使って吹き出しを作成します。

2. 吹き出しの作成方法

border で枠線を描きます。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        color:#fff;
        border-style:solid; 
        border-width:20px;
        border-color:red blue green yellow;
        width :100px;
        height:100px;
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble"></div>
  </body>
</html>


実行結果:


枠線の幅を変更します。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red blue green yellow;
        width :100px;
        height:100px;
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble"></div>
  </body>
</html>


実行結果:


枠の幅と高さを 0 にします。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red blue green yellow;
        width :0px;
        height:0px;
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble" style=""></div>
  </body>
</html>


実行結果:


左、右、下の線を透明(transparent)にします。
すると、▼だけになります。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red transparent transparent transparent;
        width :0px;
        height:0px;
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble" style=""></div>
  </body>
</html>


実行結果:


▼の上に枠を付けます。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red transparent transparent transparent;
        width :0px;
        height:0px;
        
        margin-left:12px; /* ▼の位置を右にずらす */
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div style="width:200px; height:100px; color:#fff; background-color:red; border-radius: 8px;">
      こんにちは
    </div>
    <div class="speech_bubble"></div>
  </body>
</html>


実行結果:


:after を使って、classを追加するだけで、吹き出しになるようにします。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        position:relative;
        color:#fff;
        background-color:red;
        border-radius: 8px;
      }
      .speech_bubble:after {
        content: "";
        position:absolute;
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red transparent transparent transparent;
        width :0px;
        height:0px;
        left:20px;    /* ▼の横の位置 */
        bottom:-30px; /* ▼の縦の位置。線の幅によって変更する */
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble" style="width:200px; height:100px;">
      こんにちは
    </div>
  </body>
</html>


実行結果:


▼の位置を中央揃えにします。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HTML・CSS・JavaScript</title>
    <style>
      .speech_bubble {
        position:relative;
        color:#fff;
        background-color:red;
        border-radius: 8px;
      }
      .speech_bubble:after {
        content: "";
        position:absolute;
        color:#fff;
        border-style:solid; 
        border-width:20px 10px 10px 10px;
        border-color:red transparent transparent transparent;
        width :0px;
        height:0px;
        margin-left:-10px; left:50%; /* ▼の横の位置。中央揃え */
        bottom:-30px;                /* ▼の縦の位置。線の幅によって変更する */
      }
    </style>
  </head>
  <body style="margin:0px; padding:8px; background-color:#000;">
    <div class="speech_bubble" style="width:200px; height:100px;">
      こんにちは
    </div>
  </body>
</html>


実行結果:


YouTube X

新着一覧

  • テーブル結合(CROSS JOIN、INNER JOIN、LEFT JOIN)MariaDB
  • 楽観ロック・悲観ロックMariaDB
  • カレントリードMariaDB
  • インデックスMariaDB
  • 論理削除(ソフトデリート)MariaDB
  • awk(オーク)の使い方についてLinux
  • NOT NULL 制約と NULL を許容した時の動作MariaDB
  • 外部キー制約MariaDB
  • MySQL と MariaDB の関係MariaDB
  • Docker で PostgreSQL のコンテナの使用Linux

アーカイブ

  • 2026/01
  • 2025/12
  • 2025/11
  • 2025/10
  • 2025/09
  • 2025/08
  • /00

以前のカテゴリー一覧

  • CakePHP3
  • CentOS7
  • HTML・CSS・JavaScript
  • Haskell
  • JavaScript
  • Kotlin
  • Laravel5
  • PHP
  • Python
  • Ruby
  • RubyOnRails5
  • TypeScript
  • Vue.js
  • Webサーバ講座
  • Webプログラミング講座
  • jQuery
  • linux
  • パソコン講座
  • ブログ
  • プログラミング講座
  • メモ帳作成講座
  • 数学

Copyright © 9cubed. All Rights Reserved.

プライバシーポリシー 利用規約
▲