CSS Property Value How to - div:before; add custom border








Question

We would like to know how to div:before; add custom border.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--from  ww  w.j av  a  2  s .  c o  m-->
  padding: 5px;
  border: 15px solid red;
  border-top: 0;
  position: relative;
  padding-top: 20px;
}

div:before {
  content: '';
  display: block;
  background: black;
  height: 15px;
  padding: 0 15px;
  width: 100%;
  position: absolute;
  top: 0;
  left: -15px;
}
</style>
</head>
<body>
  <div>test</div>
</body>
</html>

The code above is rendered as follows: