The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> html vs body tag for setting margin 0
mp3909
post May 5 2020, 12:00 PM
Post #1


Novice
**

Group: Members
Posts: 20
Joined: 4-April 20
Member No.: 27,264



So I want to have zero margins on my body so I thought if i do the following it would work, but it didn't.

CODE
html {
    margin: 0;
}



But then i did this and it worked.

CODE
body {
    margin: 0;
}



I'm confused why it did not work when I used the html selector to set margins to zero.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 5 2020, 02:12 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



Most browsers use a default margin for BODY, but not for the HTML element.

Here's a list of all(?) HTML elements, though I'm not sure how correct it is. Also browsers may use (or have used) different default styling: https://www.w3schools.com/cssref/css_default_values.asp

There also an official but less readable list for HTML4 elements here: https://www.w3.org/TR/CSS2/sample.html (haven't found an official one for HTML5 yet).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 5 2020, 03:32 PM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



QUOTE(Christian J @ May 5 2020, 09:12 PM) *

There also an official but less readable list for HTML4 elements here: https://www.w3.org/TR/CSS2/sample.html (haven't found an official one for HTML5 yet).


And not complete unless older browsers are ignored. Some browsers used to use padding on body, and maybe their offspring still do if in Quirks Mode, I don't know. I don't think any browser has applied styling to HTML though.
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
mp3909
post May 9 2020, 06:42 AM
Post #4


Novice
**

Group: Members
Posts: 20
Joined: 4-April 20
Member No.: 27,264



ok, thanks guys. smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 01:13 AM