HTML Element Style How to - Create a triangle div with CSS








Question

We would like to know how to create a triangle div with CSS.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.arrow-up:after {<!--from  w  ww.  jav  a  2s.c o m-->
  position: absolute;
  content: "";
  width: 0;
  height: 0;
  margin-top: 1px;
  margin-left: 2px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid white;
}

.arrow-up:before {
  position: absolute;
  content: "";
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 12px solid black;
}
</style>
</head>
<body>
  <div class="arrow-up"></div>
</body>
</html>

The code above is rendered as follows: