Day 48: inset 0

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;
}

My blog doesn’t support comments yet, but you can reply via blog@matuzo.at.


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović

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;
}

My blog doesn't support comments yet, but you can reply via blog@matuzo.at.


This content originally appeared on Manuel Matuzović - Blog and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2022-11-30T00:00:00+00:00) Day 48: inset 0. Retrieved from https://www.scien.cx/2022/11/30/day-48-inset-0-2/

MLA
" » Day 48: inset 0." Manuel Matuzović | Sciencx - Wednesday November 30, 2022, https://www.scien.cx/2022/11/30/day-48-inset-0-2/
HARVARD
Manuel Matuzović | Sciencx Wednesday November 30, 2022 » Day 48: inset 0., viewed ,<https://www.scien.cx/2022/11/30/day-48-inset-0-2/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 48: inset 0. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/30/day-48-inset-0-2/
CHICAGO
" » Day 48: inset 0." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2022/11/30/day-48-inset-0-2/
IEEE
" » Day 48: inset 0." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2022/11/30/day-48-inset-0-2/. [Accessed: ]
rf:citation
» Day 48: inset 0 | Manuel Matuzović | Sciencx | https://www.scien.cx/2022/11/30/day-48-inset-0-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.