CSS Layout How to - Set width using calc function








Question

We would like to know how to set width using calc function.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.notes {<!--from w ww. j a  v a  2  s.  c om-->
  border: 1px solid red;
}

textarea {
  width: calc(100% - 20px);
  margin: auto;
  display: block;
}
</style>
</head>
<body>
  <div class="notes">
    <h2>Title</h2>
    <textarea></textarea>
    <br>
    <button>Save</button>
  </div>
</body>
</html>

The code above is rendered as follows: