Page Widget How to - Create ruler like dashed border








Question

We would like to know how to create ruler like dashed border.

Answer


<p>
Code revised from http://fiddle.jshell.net/austinpray/fLdUD/
</p>
<!--   w  ww  .  j a  va 2  s . com-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.box {
  position: relative;
  width: 19em;
  height: 19em;
  margin: 2em auto 0;
  z-index: 1;
  color: gray;
}
.box:after {
  background: #EEE;
  content: " ";
  position: absolute;
  z-index: -1;
  top: -.5em;
  left: -.5em;
  width: 19em;
  height: 19em;
}

.box:before {
  position: absolute;
  z-index: -2;
  top: -1em;
  left: -1em;
  width: 20em;
  height: 20em;
  background: #000;
  content: " ";
  background-color: #f1f1f1;
  background-image: linear-gradient(transparent, transparent 1px),
    linear-gradient(transparent 1px, transparent 2px),
    linear-gradient(rgba(0, 0, 0, .3) 2px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, .3) 2px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -1px -1px, -1px -1px, -1px -1px, -1px -1px;
}
</style>
</head>
<body>
  <div class="box">
  
  </div>
</body>
</html>

The code above is rendered as follows: