[SOLVED] How do the symbols * . and # apply to IDs differently?

This is a discussion on "[SOLVED] How do the symbols * . and # apply to IDs differently?" within the Web Page Design section. This forum, and the thread "[SOLVED] How do the symbols * . and # apply to IDs differently? are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 9th, 2007, 16:20
Junior Member
Join Date: Jan 2007
Location: UK
Age: 23
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Inkers Send a message via MSN to Inkers
[SOLVED] How do the symbols * . and # apply to IDs differently?

So I've been doing some site reading and have been plowing through source CSS to see how 'other people' do it to get a grip on how CSS can be applied and what magic it makes happen.

There is one thing I'm a bit unsure about though. Reading through, I've often seen the symbols *, . or # applied in front of an ID or applied at least somewhere in the first line.

At first I thought that # was instead of 'div ID' to make things shorter and tidier but now I'm not sure. Would someone be able to explain to me how the symbols are used in CSS and how their application differentiates from the others? i.e using * instead of # and so on.

I'd be hugely grateful
Reply With Quote

  #2 (permalink)  
Old Nov 9th, 2007, 16:24
Aso's Avatar
Aso Aso is offline
Chief Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,010
Blog Entries: 2
Thanks: 5
Thanked 23 Times in 20 Posts
Send a message via Skype™ to Aso
Re: How do the symbols * . and # apply to IDs differently?

# in css indicates an ID. Say if in your html you have
Code: Select all
 <div id="menu">text...</div>
You would use '#menu' in your css to apply the corresponding styles. The * symbol is a 'wild card' and applies to every element

I guess I should also mention that . is for assigning style to a class (much like an ID, but can have multiple instances in the same page)

So for
Code: Select all
<a class="link" href="#">text...</a>
You would use '.link' in your css

The only items in css that don't require the # or . or when you apply styles to html tags (body, div, a ,span etc).


Going back to the first example, 'div#menu' is effectively the same as using '#menu', the same as 'a.link is the same as '.link'. It's sometimes useful however to use the former, as you can tell straight off what tag you used that particular id or class on
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)

Last edited by Aso; Nov 9th, 2007 at 16:31.
Reply With Quote
  #3 (permalink)  
Old Nov 9th, 2007, 16:27
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How do the symbols * . and # apply to IDs differently?

Alright ... well ...

# is the symbol for ID selector ... so ... your ID
CSS
Code: Select all
#container {
   background-color: #990;
}
HTML
HTML: Select all
<div id="container">
   bla bla bla
</div>
. is the symbol for class selector which you use to determine a class name
CSS
Code: Select all
.something {
   color: #900;
}
HTML
HTML: Select all
<span class="something">bla bla bla</span>
and

* is the universal selector using this mean to apply the properties to ALL elements. Read this article - No Margin For Error
Reply With Quote
  #4 (permalink)  
Old Nov 9th, 2007, 16:27
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: How do the symbols * . and # apply to IDs differently?

In the css you you will have '*','#' and '.'.

Firstly the * is for a universal selector, if you use this, this will apply to ALL.

# is for an id=. You can use it like:

CSS:
Code: Select all
#test {
/* My CSS here! */
HTML:
HTML: Select all
<div id="test"></div>
Please remember ID's can be applied to anything (<span>, etc.). You should also only use ID's ONCE per page.

.'s (dots) are for class=. You can use it like:

CSS:
Code: Select all
.thisisaclassincss {

/* My Css Here! /*
}
HTML: Select all
<span class="thisisacssclass"></span>
Classes can be used as many times as you like per page!

You can also use "BODY, HTML, p, etc" in your css. Like so:

Code: Select all
body {
/* My CSS here */
}

html {
/* My CSS here */
}

p {
/* My CSS here */
}
Hope that helps!

I will try and find a website that will explain this better

EDIT: Just noticed Karinne's post! Check out her links - especailly the No Margin For Error...

Last edited by Marc; Nov 9th, 2007 at 16:29. Reason: Missed a bit!
Reply With Quote
  #5 (permalink)  
Old Nov 9th, 2007, 16:34
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How do the symbols * . and # apply to IDs differently?

"*" is the universal selector. It matches any element. For example:

Code: Select all
* {
margin: 0;
padding: 0;
}
This removes the margins and paddings from all elements. This is not usually a good idea. "*" is generally useless, but you can use it in combination with other selectors. It's also frequently used in a hack for Internet Explorer (this is bad practice).

"." denotes a class. For example:

Code: Select all
.note {
font-size: 120%;
}
This would increase the font size of all elements with the class name "note" (such as <p class="note">).

"#" denotes an ID. These are much the same as classes, but IDs must be unique; only one element can ever have an id (such as <div id="header">). IDs are more convenient to manipulate with javascript than classes are, and they also "rank" much higher than classes whenever there is a conflict of CSS rules.

Code: Select all
#header {
background: #000;
}
This sets the background of the item with ID "header".
Reply With Quote
  #6 (permalink)  
Old Nov 9th, 2007, 16:35
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: How do the symbols * . and # apply to IDs differently?

LOL 3 people replyed with *nearly* the same thing Although, mine isnt as good as the other two... I only knocked it up in a minute whilst typing an email!
Reply With Quote
  #7 (permalink)  
Old Nov 9th, 2007, 16:36
Aso's Avatar
Aso Aso is offline
Chief Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,010
Blog Entries: 2
Thanks: 5
Thanked 23 Times in 20 Posts
Send a message via Skype™ to Aso
Re: How do the symbols * . and # apply to IDs differently?

lol, enough info for you ?
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Reply With Quote
  #8 (permalink)  
Old Nov 9th, 2007, 16:43
Junior Member
Join Date: Jan 2007
Location: UK
Age: 23
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Inkers Send a message via MSN to Inkers
Re: How do the symbols * . and # apply to IDs differently?

Ahhhh, I see! That makes a lot of sense! Thanks everyone!
Reply With Quote
  #9 (permalink)  
Old Nov 14th, 2007, 03:58
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: [SOLVED] How do the symbols * . and # apply to IDs differently?

I wish to add my example but, I'm afraid someone will delete my thread for clearing up... lol
All the example given above is very cristal clear..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbols in CSS pallworthy Web Page Design 4 Apr 17th, 2008 20:34
using “”-_()&,\ Symbols wireman54301 Hosting & Domains 0 Apr 18th, 2006 06:01
designed a website in CSS but displays differently in other browsers skyfire400 Web Page Design 8 Jan 25th, 2006 11:53
Fonts display differently in FF and IE Chico Web Page Design 4 Jan 2nd, 2006 12:52
Simple HTML displayed differently between browsers RichRadio2005 Web Page Design 0 Nov 29th, 2005 14:04


All times are GMT. The time now is 21:57.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43