|
|
 |
November 9th, 2007, 12:20 PM
|
#1
|
|
New Member
Join Date: Jan 2007
Location: UK
Age: 24
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
[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 
|
|
|
November 9th, 2007, 12:24 PM
|
#2
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
Re: How do the symbols * . and # apply to IDs differently?
# in css indicates an ID. Say if in your html you have
Code:
<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:
<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 edited by Aso; November 9th, 2007 at 12:31 PM..
|
|
|
November 9th, 2007, 12:27 PM
|
#3
|
|
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 32
Posts: 4,608
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:
#container {
background-color: #990;
}
HTML
<div id="container">
bla bla bla
</div>
. is the symbol for class selector which you use to determine a class name
CSS
Code:
.something {
color: #900;
}
HTML
<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
|
|
|
November 9th, 2007, 12:27 PM
|
#4
|
Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
|
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:
#test {
/* My CSS here! */
HTML:
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:
.thisisaclassincss {
/* My Css Here! /*
}
<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:
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... 
__________________
Regards
Marc
Administrator - Webforumz.com
Want to be a moderator? Please contact me.
Last edited by Marc; November 9th, 2007 at 12:29 PM..
Reason: Missed a bit!
|
|
|
November 9th, 2007, 12:34 PM
|
#5
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 28
Posts: 1,107
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:
* {
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:
.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:
#header {
background: #000;
}
This sets the background of the item with ID "header".
|
|
|
November 9th, 2007, 12:35 PM
|
#6
|
Join Date: Apr 2007
Location: Scotland, UK
Posts: 2,086
Thanks: 2
Thanked 23 Times in 23 Posts
|
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!
__________________
Regards
Marc
Administrator - Webforumz.com
Want to be a moderator? Please contact me.
|
|
|
November 9th, 2007, 12:36 PM
|
#7
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
Re: How do the symbols * . and # apply to IDs differently?
lol, enough info for you  ?
|
|
|
November 9th, 2007, 12:43 PM
|
#8
|
|
New Member
Join Date: Jan 2007
Location: UK
Age: 24
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: How do the symbols * . and # apply to IDs differently?
Ahhhh, I see! That makes a lot of sense! Thanks everyone! 
|
|
|
November 13th, 2007, 11:58 PM
|
#9
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,629
Thanks: 0
Thanked 4 Times in 3 Posts
|
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..
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Symbols in CSS
|
pallworthy |
HTML, XHTML and CSS |
4 |
April 17th, 2008 04:34 PM |
|
using “”-_()&,\ Symbols
|
wireman54301 |
Web Hosting and Domains |
0 |
April 18th, 2006 02:01 AM |
|
designed a website in CSS but displays differently in other browsers
|
skyfire400 |
HTML, XHTML and CSS |
8 |
January 25th, 2006 07:53 AM |
|
Fonts display differently in FF and IE
|
Chico |
HTML, XHTML and CSS |
4 |
January 2nd, 2006 08:52 AM |
|
Simple HTML displayed differently between browsers
|
RichRadio2005 |
HTML, XHTML and CSS |
0 |
November 29th, 2005 10:04 AM |
|