[Help] Why doesn't my <section> reach the edge of the page?
I put 0 margin, border, and padding on my span but it still won't reach the edge of the page. What am I misunderstanding?
Posted Aug 22, 2019, 1:46 PM UTC
811
I put 0 margin, border, and padding on my span but it still won't reach the edge of the page. What am I misunderstanding?
Posted Aug 22, 2019, 1:46 PM UTC
Most browsers give the body element a margin on default.
Simply add the following to your body style:
Libaries like https://necolas.github.io/normalize.css/ try to make all browsers render more consistently (or universal), by overriding the defaults.
Normalize github: https://github.com/necolas/normalize.css/
awesome thanks! may I ask another question? Why can I do `width: 100%` and get the background color to fill the screen horizontally but `height: 100%` doesn't fill the screen vertically? I need to specify the height in absolute measurements, px or vh or something.
Because most browsers give the body element the
display:blockproperty by default. This property makes the element (body in this case) take up the whole width, but not the height. The default height property isheight:auto, which makes it so its height is based on its contents/childrens height (unless those are absolutely positioned or floated).So that's why you have to explicitly set the height, but not the width.
Explicitly setting the height to a percentage still doesn't work because it's relative to its parent. You'd need to set the html and body element to
height: 100%in order for any child element to properly use the same property, ad infinitum.The best way to accomplish what they're probably looking for is using
vhunits withmin-height: 100vh;. min-height allows your content to still expand the element if larger than the viewport height.That's right, thanks for the heads up.
So how do you deal with that? I can see why it'd be useful in the http1.1 days but with http2 it just seems unnecessary
You know we are on HTML5, right?
Browser defaults are defaults to give consistency. However, they aren't always the consistency we as devs want. Learn about CSS resets. Dead useful. My default is:
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
Another comment has it explained perfectly.
If you're trying to make the entire background of your site a specific color, add a background to the <body> element itself in your stylesheet. This is a better way instead of creating child elements inside the elements you're trying to style.
Cheers!