0

I have a div inside the html's body,why is it when I set it's position to absolute I can set it's width/height using percentages?The parent element doesn't have any set width/height so where does the child element get it's reference size from?I have added my code bellow.

div {
  position: absolute;
  width: 80%;
  height: 40%;
  background-color: red;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" type="text/css" href="wut.css">
</head>

<body>

  <div>

  </div>

</body>

</html>
johannchopin
  • 13,720
  • 10
  • 55
  • 101
a55t0a55
  • 11
  • 1
  • When you set `position:absolute;` on an element it becomes relative to the nearest positioned ancestor, if none exists it is then relative to the initial containing block that is `viewport/`, and the `viewport/` have dimesnions – Rainbow Apr 19 '20 at 19:16
  • from the duplicate read : *Absolute Positioning Exception* – Temani Afif Apr 19 '20 at 19:19

0 Answers0