CSS Layout How to - Set calc width








Question

We would like to know how to set calc width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.box1 {<!-- w  ww  .  ja v a  2  s .  c om-->
  width: 50px;
  height: 100px;
  background: red;
  float: left;
}

.box2 {
  width: calc(( 100% - 50px)/3);
  height: 100px;
  background: yellow;
  float: left;
}

.box3 {
  width: calc(( 100% - 50px)/3);
  height: 100px;
  background: blue;
  float: left;
}

.box4 {
  width: calc(( 100% - 50px)/3);
  height: 100px;
  background: green;
  float: left;
}
</style>
</head>
<body>
  <div class="box1"></div>
  <div class="box2"></div>
  <div class="box3"></div>
  <div class="box4"></div>
</body>
</html>

The code above is rendered as follows: