cssで吹き出しの実装方法

2026年1月6日 CSS,吹き出しの作り方

cssで吹き出しの実装方法

html

<section class="css_fuki_section">
        <div class="section_inner">
          <h2 class="section_title">吹き出しのサンプル</h2>
          <div class="fuki_wrapper">
            <div class="fuki fuki_left_with_img">
              <img src="images/fuki1.png" alt="左画像" class="fuki_img" />
              <div class="fuki_text_left">
                こんにちは!これは画像付き左向きの吹き出しです。こんにちは!これは画像付き左向きの吹き出しです。こんにちは!これは画像付き左向きの吹き出しです。
              </div>
            </div>
            <div class="fuki fuki_right_with_img">
              <div class="fuki_text_right">
                こんにちは!これは画像付き右向きの吹き出しです。こんにちは!これは画像付き右向きの吹き出しです。こんにちは!これは画像付き右向きの吹き出しです。こんにちは!これは画像付き右向きの吹き出しです。
              </div>
              <img src="images/fuki2.png" alt="右画像" class="fuki_img" />
            </div>
          </div>
        </div>
      </section>


.css_fuki_section {
  width: 100%;
  margin-block: 100px;
  /* 必要に応じてmin-heightを調整 */
}

.section_inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-top: 50px;
}
.section_title {
  position: relative;
  font-size: min(2.78vw, 40px);
  font-weight: bold;
  color: var(--text-color);
  text-align: left;
  margin-bottom: min(1.39vw, 20px);
  padding-left: 15px;
}
.section_title::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background-color: var(--black--);
}

/*---------------吹き出しの詳細設定--------------------*/
.fuki_wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fuki_left_with_img,
.fuki_right_with_img {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.fuki_left_with_img {
  flex-direction: row;
  justify-content: flex-start;
}
.fuki_right_with_img {
  flex-direction: row;
  justify-content: flex-end;
}
.fuki_img {
  max-width: 300px;
  margin: 0 8px;
}
.fuki_text_left,
.fuki_text_right {
  position: relative;
  background: #f0f0f0;
  border-radius: 16px;
  padding: 12px 16px;
  max-width: 60%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-size: min(1.6vw, 16px);
}

.fuki_text_left::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 20px;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 16px solid #f0f0f0;
}

.fuki_text_right::before {
  content: "";
  position: absolute;
  right: -16px;
  top: 20px;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid #f0f0f0;
}

@media screen and (max-width: 768px) {
  .section_inner {
    width: 100%;
    margin: 0 auto;
    padding-top: 50px;
  }
  .section_title {
    position: relative;
    font-size: min(2.78vw, 40px);
  }
  .section_title::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 5px;
    height: 100%;
    background-color: var(--black--);
  }
  .fuki_img {
    width: min(30.078125vw, 230px);
    margin: 0 8px;
  }
  .fuki_text_left,
  .fuki_text_right {
    font-size: min(2.083333333333333vw, 16px);
  }
}

@media screen and (max-width: 450px) {
  .fuki_img {
    width: min(40.22222222222222vw, 180px);
  }
  .fuki_text_left,
  .fuki_text_right {
    font-size: min(3.111111111111111vw, 14px);
  }
}
サイトはコチラから