Dynamically Sizing a Contained Element | Task

Ole Ersoy
Jan - 14  -  1 min

Scenario

We want the width and height of our div element to be whatever the width and height of the containing element is minus 1rem.

Approach

Use calc . The containing element will be a main element. This is the CSS.

div {
  height: calc(100% - 1rem);
  width: calc(100% - 1rem);
  background-color: aqua;
}

Demo