0

Let's say I have a simple page structure like this:

body {
    overflow: hidden;
}

body>div {
    border: 1px solid black;
}

.container {
    overflow: auto;
    height: 97vh;
    width: 97vw;
}

.content {
    width: 5000px;
    height: 5000px;
}
<body>
    <div class="container">
        <div class="content">
        </div>
    </div>
</body>

As you can see in maximized window, height of element content is 97% of viewport height, which is what I expect. But as soon as I start to decrease the height of the browser window, this element loses its 97%, approaches 100%, until it reaches a point where it is almost impossible to see the bottom scroll bar.

Shouldn't it still be at 97%? And how can I achieve it?

Petr Nečas
  • 426
  • 3
  • 11

1 Answers1

0

Because the browser applies some default CSS. For the <body> it is :

body {
    display: block;
    margin: 8px;
}

You need to overwrite the default margin:8px by writing :

body {
    margin: 0;
}

You can also use a ready-made CSS reset file.

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63