...

View Full Version : * {margin: 0}



_com
08-20-2005, 03:11 PM
Here we set everytime the margin to null in every css declaration:


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 ??


* {margin: 0}
div#someDiv ul#someList {width: 275px;}
div#someDiv2 ul#someList2 {width: 550px;}

mark87
08-20-2005, 03:43 PM
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.

_com
08-20-2005, 04:19 PM
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


/* universal selector to reset non-explicit set margins to zero */
* {margin: 0;}, all that elements will inherit margin:0.

harbingerOTV
08-22-2005, 12:37 AM
to jump on the bandwagon here can anyone clarify this?

I have been using the


* {
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:


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?

mark87
08-22-2005, 01:27 AM
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.

rmedek
08-22-2005, 01:33 AM
This...

* {
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 = :cool:

harbingerOTV
08-22-2005, 02:13 AM
BTW, our friend here MindlessLemming discovered this snippet.

Andrew = :cool:

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.

rmedek
08-22-2005, 03:15 AM
Questions not answered? :confused:

http://richardmedek.com/temp/padding.htm

harbingerOTV
08-22-2005, 04:03 AM
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?

mindlessLemming
08-22-2005, 04:17 AM
BTW, our friend here MindlessLemming discovered this snippet.

Andrew = :cool:

lol, cheers Rich -- the cheque's in the mail, I swear ;)

original article: http://leftjustified.net/journal/2004/10/19/global-ws-reset/

rmedek
08-22-2005, 09:00 PM
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...

mrruben5
08-23-2005, 01:53 AM
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.


* {
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

zro@rtv
08-23-2005, 03:44 AM
my guess is that yr thinkin * was an ie thing has to do with the

* 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?)

bazz
08-23-2005, 11:11 AM
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 :p

Bazz

Tristan Gray
08-23-2005, 12:48 PM
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...

_com
08-23-2005, 09:54 PM
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...

any idea this applies to classes and ids as well

rmedek
08-24-2005, 01:01 AM
It applies to everything. Once you use "* {margin: 0; padding: 0}", nothing on the page will have any margin or padding. NOTHING. Nada. Zero items. Ix nay on the addingpay and arginsmay.

Then you add margin and padding where you want it.

_com
08-24-2005, 06:15 PM
Also every browser has different default margins and paddings -so this helps to zero them all.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum