Page Widget How to - Create CSS3 Speech bubble








Question

We would like to know how to create CSS3 Speech bubble.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
p.speech {<!--  www.j  a  va 2 s.c om-->
  position: relative;
  width: 200px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  background: #fff;
  border: 2px solid #666;
  -moz-border-radius: 30px;
  -webkit-border-radius: 30px;
  border-radius: 30px;
  -moz-box-shadow: 2px 2px 4px #888;
  -webkit-box-shadow: 2px 2px 4px #888;
  box-shadow: 2px 2px 4px #888;
}

p.speech:before {
  content: " ";
  width: 0;
  height: 0;
  position: absolute;
  top: 100px;
  left: 30px;
  border: 25px solid #666;
  border-color: #666 transparent transparent #666;
}

p.speech:after {
  content: " ";
  width: 0;
  height: 0;
  position: absolute;
  top: 100px;
  left: 38px;
  border: 15px solid #fff;
  border-color: #fff transparent transparent #fff;
}
</style>
</head>
<body>
  <p class="speech">java2s.com
  </p>
</body>
</html>

The code above is rendered as follows: