Day 48: inset 0

posted on

It’s time to get me up to speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve started #100DaysOfMoreOrLessModernCSS. Why more or less modern CSS? Because some topics will be about cutting-edge features, while other stuff has been around for quite a while already, but I just have little to no experience with it.


On day 9 I’ve talked about the inset shorthand properties inset, inset-inline, and inset-block. I don’t believe that I will need those often, but inset can come in handy when you want one element to fill another element entirely.

If you have an outer element and an inner element and you want the inner element to fill its parent, you can use absolute positioning and set top, right, bottom, and left to 0.

<div class="outer">
  <div class="inner">
  </div>
</div>
.outer {
  border: 10px solid hotpink;
  position: relative;
  width: 7rem;
  height: 7rem;
}

.inner {
  background: aqua;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

Instead, you could also just set inset to 0.

.inner {
  position: absolute;
  inset: 0;
  background: aqua;
}

Of course, this also applies to a fixed positioned element that you want to fill the viewport with.

.inner {
  position: fixed;
  inset: 0;
  background: aqua;
}

See on CodePen

Further reading

Overview: 100 Days Of More Or Less Modern CSS