13 replies [Last post]
anna_single16
anna_single16's picture
Offline
newbie
ok
Last seen: 12 years 21 weeks ago
ok
Joined: 2007-03-26
Posts: 8
Points: 0

:jawdrop:

hi,

could you tell me what is this asterisk all about, pls. take a look at this below,
* {
margin: 0;
padding: 0;
}

what this character --> * can do? what is this for?

thanks in advance.

Triumph (not verified)
Anonymous's picture
Guru

It's a wild card. It means

It's a wild card. It means "everything".

anna_single16
anna_single16's picture
Offline
newbie
ok
Last seen: 12 years 21 weeks ago
ok
Joined: 2007-03-26
Posts: 8
Points: 0

what it can do? could you

what it can do?
could you give me a basic scenario for this wildcard?

Triumph (not verified)
Anonymous's picture
Guru

anna_single16 wrote:what it

anna_single16 wrote:
what it can do?
could you give me a basic scenario for this wildcard?

Just like in your example above. * {
margin: 0;
padding: 0;
}

That causes everything to have no margin and no padding. Everything on the page. Absolutely everything.

anna_single16
anna_single16's picture
Offline
newbie
ok
Last seen: 12 years 21 weeks ago
ok
Joined: 2007-03-26
Posts: 8
Points: 0

Does this wildcard affect

Does this wildcard affect all

?

how about let say i'll override it like this below,

* {
margin: 0;
padding: 0;
}

// override.
h1 {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 16px;
color: #986161;
padding: 8px 8px 4px;
}

ok, what will happen now, does this will override the asterisk character?
or it has no effect at all?

thanks in advance.

Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 3 years 47 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

Yes it does. Stylesheets are

Yes it does. Stylesheets are read from top to bottom. Anything that comes later in the sheet overrides things that come earlier.

You just use the * (universal selector) to zero everything first, and then style from there.

Life's a journey. Enjoy the trip.

anna_single16
anna_single16's picture
Offline
newbie
ok
Last seen: 12 years 21 weeks ago
ok
Joined: 2007-03-26
Posts: 8
Points: 0

thanks guys

thanks guys :rolleyes:

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 47 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Anna you probably ought to

Anna you probably ought to read through this page from the W3C explaining the various selectors so you have better understanding of how they work and what are available (bearing in mind that not all selectors are supported by all browsers, which it doesn't cover)

http://www.w3.org/TR/REC-CSS2/selector.html

And I would also have a read through the specs on cascade and inheritence of CSS rules, which a slightly harder page to to understand but covers important fundemental aspects of how things are handled

http://www.w3.org/TR/REC-CSS2/cascade.html

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 16 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

You also don't want to use

You also don't want to use that, it's called a "global reset".

Have a look here:

http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/

Verschwindende wrote:
  • CSS doesn't make pies

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 47 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

zero default rules are a

zero default rules are a debatable issue but cos Meyers pronounced on the subject everyone is slavishly following, without I doubt having any real understanding of what the extended rulesets are designed to cope with :shrug:

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 16 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

Well yes, I still

Well yes, I still occasionally use a * reset, but I just thought I'd throw it in there Wink

Verschwindende wrote:
  • CSS doesn't make pies

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 5 years 8 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Hugo wrote:but cos Meyers

Hugo wrote:
but cos Meyers pronounced on the subject

With some well backed-up evidence. The global reset screws with forms elements.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 11 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Phreestyle wrote:Yes it

Phreestyle wrote:
Yes it does. Stylesheets are read from top to bottom. Anything that comes later in the sheet overrides things that come earlier.

You just use the * (universal selector) to zero everything first, and then style from there.

You're right, but you're also wrong.

Style rules are applied according to their specificity. More specific rules applying before less specific rules. If two or more rules affecting the same element have the same specificity, the last one wins.

The universal selector has less specificity than any other selector, ie. it doesn't matter where the * selector rules are placed with respect to other rules, the other rules will always override the * selector rules.

However, a sensible style sheet organisation strategy is to place the more general rules first. That is, *, then element tag rules, then common classes then ids and descendent styles.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 47 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Tyssen wrote:Hugo wrote:but

Tyssen wrote:
Hugo wrote:
but cos Meyers pronounced on the subject

With some well backed-up evidence. The global reset screws with forms elements.

I wasn't knocking Meyer (dodgy out of context quoting Smile) and yes was aware of the problem with the universal reset. Trouble is not so much with resets per se but more with possibly people not being aware of the critical nature of controlling default settings whatever approach is taken.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me