Page Widget How to - Create CSS Triangle Border








Question

We would like to know how to create CSS Triangle Border.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.triangle {<!--  www .jav  a 2s. c o m-->
  position: relative;
  width: 0;
  border-bottom: solid 50px black;
  border-right: solid 30px transparent;
  border-left: solid 30px transparent;
}

.triangle .empty {
  position: absolute;
  top: 9px;
  left: -21px;
  width: 0;
  border-bottom: solid 36px white;
  border-right: solid 21px transparent;
  border-left: solid 21px transparent;
}
</style>
</head>
<body>
  <div class="triangle">
    <div class="empty"></div>
  </div>
</body>
</html>

The code above is rendered as follows: