CSS Simple Speech Bubble

02/03/2021

Contents

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Simple Speech Bubble</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <div class="box">
        <img class="account" src="ic_account.svg" alt="">
        <div class="bubble"><h1>CSS Simple<br>Speech Bubble</h1></div>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #f0e099;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 100%;
  height: 100vh;
  padding: 15px;
}
.box {
  display: grid;
  grid-template-columns: 20% 77%;
  grid-column-gap: 3%;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  max-width: 360px;
  height: auto;
}
.account {
  width: 100%;
  margin: 0 auto;
}
.bubble {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 100%;
  height: 100%;
  padding: 20px 0;
  border: solid 2px #3d3935;
  border-radius: 6px;
  background-color: #fff;
  color: #3d3935;
  font-size: 1rem;
  text-align: center;
}
.bubble:before {
  position: absolute;
  top: 30px;
  left: -21px;
  width: 0px;
  height: 0px;
  border-top: 10px solid transparent;
  border-right: 10px solid #3d3935;
  border-bottom: 10px solid transparent;
  border-left: 10px solid transparent;
  content: "";
}
.bubble:after {
  position: absolute;
  width: 0px;
  height: 0px;
  top: 32px;
  left: -16px;
  border-top: 8px solid transparent;
  border-right: 8px solid #fff;
  border-bottom: 8px solid transparent;
  border-left: 8px solid transparent;
  content: "";
}
.bubble h1 {
  margin: 0;
  color: #3d3935;
  font-size: 1.75rem;
}
@media screen and (max-width: 480px) {
  .bubble h1 {
    font-size: 1.25rem;
  }
}