2

The red #container element doesn't seem to take up all the available space in the document, even when it's width is set to 100%. There seems to be some extra padding in the html element, but even when I set it's padding to 0 it's still there.

How could I fix this? Thanks in advance.

Demo code:

body, html {
  width: 100%;
  height: 100%;
}
#container {
  width: 100%;
  height: 100%;
  background-color: red;
}
<body>
  <div id='container'></div>
</body>

JsFiddle here

1
  • you only have this margin in most of the "snippet", "fiddle" to the body, on a normal html page, you wont have that. So just add margin:0; to your body Commented Jun 2, 2022 at 15:26

2 Answers 2

1

You have to add padding: 0 and margin: 0 to:

body, html {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Answer does not show the suggested changes to the code in the code block.
It clearly states what the OP has to do, simple english interpretation, hence the to:
0

Try adding margin: 0px; to your CSS:

body,
html {
  width: 100%;
  height: 100%;
  margin: 0px;
}

Seems to be working here:

https://jsfiddle.net/k2boqeLt/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.