Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Ronald Roe

Thread: CSS- *{} Versus Body{} ?

  1. #1
    Junior Member
    Join Date
    Dec 2016
    Posts
    17
    Member #
    55967
    Liked
    1 times

    CSS- *{} Versus Body{} ?

    CSS - *{} Versus Body{} ?

    Is there a huge advantage from one over the other?
    Is there an industry preference?

    Thanks

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    body only selects the body element, so only those properties that would be inherited would propagate to other elements. so, if you set margin: 20px; on body, only the body will have that.

    * selects literally everything, so if you set margin: 20px; on that, every single element on the whole site will have a 20px margin unless it's overridden somewhere.

    In essence, they don't really compare at all.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Junior Member
    Join Date
    Dec 2016
    Posts
    17
    Member #
    55967
    Liked
    1 times
    Ahh, ok. So, What I'm getting is, the *{} should be used as the basis / starting point for a CSS file?
    As you use <!DOCTYPE HTML> <html> <head><title></title>
    </head></html>, as a basis/starting point for a page?

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Not necessarily. It just depends on what you need. For most projects, I use a CSS reset to wipe out the browsers' default styles. That uses * to remove padding and margin from every element, and then after that, I add it back in where appropriate. But, if your project doesn't need that, there's no point in adding it.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  6. #5
    Junior Member
    Join Date
    Dec 2016
    Posts
    17
    Member #
    55967
    Liked
    1 times
    Hm, I believe I get it, so use body{} unless the * is needed for a particular purpose?
    Seems most of the video tutorials I watch, use the *{}. I've also got the Missing Manual CSS, but I don't remember what it said about the matter. Do you know this book? If so, do you have an opinion about the book?

    Thanks again for the help.
    Last edited by ScottAC; Nov 10th, 2017 at 11:58 PM.

  7. #6
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    I honestly have never read a book about CSS or HTML...or JavaScript. It's hard for me to learn that way. I need to see someone do it, then try myself.
    ScottAC likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:27 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com