HTML Element Style How to - Add border to Div grid








Question

We would like to know how to add border to Div grid.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.box {<!--from   www.j a v  a 2s. c  o  m-->
  width: 33%;
  float: left;
  box-sizing: border-box;
  display: inline-block;
  border-left: 1px solid black;
  border-top: 1px solid black;
}

.outer {
  width: 100%;
  height: auto;
  line-height: 0;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
}

.clearboth {
  clear: both;
}
</style>
</head>
<body>
  <div class="outer">
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <div class="box">
      <h2>DIV</h2>
    </div>
    <br class="clearboth" />
  </div>
</body>
</html>

The code above is rendered as follows: