Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Why this guy use body class and body selector both?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #174475
    ravinder07
    Participant

    Hi, I was watching a video tutorial to make a responsive website from scratch in html5 and css3 on youtube : http://www.youtube.com/watch?v=eOG90Q8EfRo

    In this video this guy use Body selector to style html body and also use body class to add style….since i am new i just want to know is there any point to use selector and class
    body {
    background-image: url(‘img/bg.png’);
    color: #000305;
    font-size: 87.5%; /* Base font size: 14px */
    font-family: ‘Trebuchet MS’, Trebuchet, ‘Lucida Sans Unicode’, ‘Lucida Grande’, ‘Lucida Sans’, Arial, sans-serif;
    line-height: 1.429;
    margin: 0;
    padding: 0;
    text-align: left;
    }

    .body {
    clear: both;
    margin: 0 auto; /* This guy use margin again*/__
    width: 70%;
    }

    Instead of this i am thinking to use it as

    body {
    background-image: url('img/bg.png');
    color: #000305;
    font-size: 87.5%; /* Base font size: 14px */
    font-family: 'Trebuchet MS', Trebuchet, 'Lucida      Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    line-height: 1.429;
    text-align: left;
    clear: both; 
    width: 70%;
    

    }

    Hope i asked it properly and clearly.
    Thank You

    #174479
    Paulie_D
    Member

    Unfortunately, I don’t have an hour to spend watching that video to find out why he does it…it may just be something he does.

    I don’t see much point in clearing floats on the body either but _ <shrugs>_ whatever.

    However, if you want to combine the properties into one declaration, it perfectly OK.

    Personally I don’t limit the width of the body tag, I prefer a a wrapping div but it’s a matter of choice.

    #174487
    Senff
    Participant

    It’s possible that he assigned a class to the body with a number of styles, to make it easy to remove all those styles at once (by removing the class, as opposed to removing each style one by one).

    Though I admit the name “body” for the class is a bit dodgy.

    #174488
    ravinder07
    Participant

    ok you might be right but see in code. He used margin in Body selector and body class….why he use margin property two time….. check out my code i have bold margin used by him second time in body class. He already used margin in body selector. Is it a mistake or he did it for any purpose?

    #174492
    Senff
    Participant

    Because the styles on the body tag are the “default” styles, and the styles on the class that is assigned to the body are “overriding” styles that can change from time to time. Perhaps there are situations when the class doesn’t have a margin assigned to it — in that case, the default margin of 0 will be used.

    #174493
    ravinder07
    Participant

    oh ok got it thanks…

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.