Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: * {margin: 0}

  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb * {margin: 0}

    Here we set everytime the margin to null in every css declaration:

    PHP Code:
    div#someDiv ul#someList {margin:0; width: 275px;}
    div#someDiv2 ul#someList2 {margin:0; width: 550px;} 
    Here we set the margin to null once with the universal selector to avoid
    needless repeating to set the margin to nul everytime where needed? Will this work for all browsers, though ??
    PHP Code:
    * {margin0}
    div#someDiv ul#someList {width: 275px;}
    div#someDiv2 ul#someList2 {width: 550px;} 

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't see why not.

    If you just wanted div's to have a margin of 0 though (so it doesn't affect the body etc) you could just use -

    div { margin: 0 }

    Remember that whatever is in the div will have the same margin as the parent.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In this example, that would be:
    ul {margin: 0;} or as you said: div {margin:0;}

    My assumption was that any div, ul, a, h1, h2, etc. ..., div#idName, etc. ... , .className, etc. ... where no explicit margin is set, and one would use
    PHP Code:
    /* universal selector to reset non-explicit set margins to zero */
    * {margin0;} 
    , all that elements will inherit margin:0.
    Last edited by _com; 08-20-2005 at 05:43 PM.

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,801
    Thanks
    8
    Thanked 131 Times in 129 Posts
    to jump on the bandwagon here can anyone clarify this?

    I have been using the
    Code:
    *  {
    padding : 0;
    margin : 0;
    }
    what exactly does it do. Is the * not an IE thing? Even if you do use it things like ul, li, h? still resort to thier default padding and/or margin.

    so what exactly does it do?

    I have just recently writing something like:
    Code:
    html, body, ul, ol, li, p, div, h1, h2, h3, h4  {
    padding : 0;
    margin : 0;
    list-style : none;
    }
    at the beginning of my css. Then readjusting as need be.

    is the * thing supposed to achieve the same thing?
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #5
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes the * is known as a universal selector (CSS2), so

    html, body, ul, ol, li, p, div, h1, h2, h3, h4 {
    padding : 0;
    margin : 0;
    }

    Should be the same as

    * {
    padding : 0;
    margin : 0;
    }

    Guess you could always try it out though to see what happens in different browsers but in theory it should be the same.

  • #6
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    This...
    Code:
    * {
    margin: 0;
    padding: 0;
    }
    ...means everything gets its margin and padding set to zero. Anything that once had margin or padding will have no more. "*" is a wildcard. It's not browser specific, as far as I know.

    It's used primarily so you can avoid guessing the values for padding/margin that different browsers use, and start from scratch.

    BTW, our friend here MindlessLemming discovered this snippet.

    Andrew =

  • #7
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,801
    Thanks
    8
    Thanked 131 Times in 129 Posts
    Quote Originally Posted by rmedek
    BTW, our friend here MindlessLemming discovered this snippet.

    Andrew =
    must have been where I first saw it

    So I might have been making it up then when I said that the H's and lists still retain thier default padding/margin(s). But, I could swear, that they do.
    It may have been that I had to much stuff going on in the css to notice.

    I'll store this away in the 'questions>not answered>still accepting>not sure if I'm right or wrong>have the real answer for it>still don't get>use anyway' folder.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #8
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts

  • #9
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,801
    Thanks
    8
    Thanked 131 Times in 129 Posts
    rich-

    okay I see I must have made some errors somewhere. Does the * thing have anything to conflict with the Doctype?

    Maybe my thoughts were the * was an IE thing thus I was applying margin/padding:0 to everything and thus taking up space in the css.

    I guess it's time to store it in the 'questions>answered>useful>gobal stuuf that should be included in every page>css' folder.

    good link read btw. I must have missed that. Or maybe I read it and didn't 'get' it when I did read it.

    Now that I know what it does i need to go back and relook at a few sites.

    p.s. still on tour? how close you guys coming to mobile,al?
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #10
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rmedek
    BTW, our friend here MindlessLemming discovered this snippet.

    Andrew =
    lol, cheers Rich -- the cheque's in the mail, I swear

    original article: http://leftjustified.net/journal/200...obal-ws-reset/

    I take no responsibility for the above nonsense.


    Left Justified

  • #11
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Quote Originally Posted by harbingerOTV
    p.s. still on tour? how close you guys coming to mobile,al?
    Nah, I've been back for a few weeks... just too busy to try and update/design my site. It's web world for me until October...

  • #12
    Regular Coder
    Join Date
    Nov 2004
    Location
    The Netherlands
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use the universal selector as a hack to get all to work with other box models. I find W3C's box model thinking a bit... Fill it in. I read up an article on quirksmode to see why firefox actually did this rendering so weird,

    Border-box.

    Code:
    * {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    }
    How ironic. We like firefox and mozilla for it's support of webstandards. And they still use their propiarity -moz- prefix.

    http://www.quirksmode.org/index.html?/css/box.html
    Last edited by mrruben5; 08-23-2005 at 02:59 AM.
    CATdude about IE6: "All your box-model are belong to us"

  • #13
    Regular Coder zro@rtv's Avatar
    Join Date
    Feb 2005
    Location
    on the network
    Posts
    433
    Thanks
    0
    Thanked 1 Time in 1 Post

    clarify

    my guess is that yr thinkin * was an ie thing has to do with the
    Code:
    * html div#thing
    hack to make ie-only css. The star just means "wildcard" in that situation also.

    literally meaning and div#thing thats a child of html... thats a child of ANYTHING... since ie (for ungodly reasons) thinks something is a parent of html.

    (sorry usless post and bump, but i think thats pretty interesting. what the heck does ie thik is outside <html>? another dimension?)
    ._-zro
    zro@redtv
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999

  • #14
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Blimey, I have just been using it hack for IE, without realising that it can make a difference in the other browsers - even though, so far, it hasn't.

    Still, I must be making some progress when I am now at the stage of re-learning

    Bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #15
    Regular Coder
    Join Date
    Jul 2005
    Location
    Halifax, Nova Scotia, Canada
    Posts
    392
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well it's good to use anyway because the padding and margins are not consistent across browsers so it is a good idea to automatically start everything out with none and then add as you are building.

    I'm not down with browser-specific commands at all. I doubt I ever will approve of it. I can't wait until Peter gets back and adds something other than his germs to quirksmode...
    Once I thought I was wrong but I was mistaken.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •