class id class id ???

Got a question for your instructor or classmates? Found a neat technique you want to share? Post 'em here.
User avatar
zelouzelou
Posts: 63
Joined: Mon Aug 29, 2011 7:22 pm

class id class id ???

Post by zelouzelou »

I'm still having a hard time understanding the difference between an id and a class, and when to use each.
Can someone please explain?
Kathyleen Bullard

User avatar
smith206
Posts: 100
Joined: Mon Aug 29, 2011 6:00 pm

Re: class id class id ???

Post by smith206 »

More of less it is up to you. They both basically do the same thing. There are a few differences though. IDs can only be applied to one specific object within your page so each id you use needs to be unique. Classes can be applied to as many objects as you want. So the advantage of a class is you can change multiple objects with one line of css where with ids you would need to style each id individually. There are some cool tricks you can do with css using both ids and classes but it gets quite technical.
Kyle Smith

User avatar
zelouzelou
Posts: 63
Joined: Mon Aug 29, 2011 7:22 pm

Re: class id class id ???

Post by zelouzelou »

Hmmm interesting. So is it kind of like if I wanted to style just one specific sentence within a webpage, I might use an id, whereas if I have a whole bunch of sentences scattered throughout the webpage that I want to style the same way, I might use a class and style it all at once?

Thanks Kyle!
Kathyleen Bullard

User avatar
Instructor
Site Admin
Posts: 1869
Joined: Thu Jul 21, 2011 8:51 am

Re: class id class id ???

Post by Instructor »

zelouzelou wrote:Hmmm interesting. So is it kind of like if I wanted to style just one specific sentence within a webpage, I might use an id, whereas if I have a whole bunch of sentences scattered throughout the webpage that I want to style the same way, I might use a class and style it all at once?

Thanks Kyle!
Yes and no. Both instances you're describing would probably best be filled by class styles. IDs typically are used for things like div tags and images. You might use an ID targeting a particular div to style the type within it, though.

I always think of class styles as precision instruments, use for a letter, a word, or line of type, or maybe a single image or div tag. IDs and particularly tag styles are blunt instruments that require less interaction, but give less control.
"Inspiration is for amateurs. The rest of us just show up and get to work." — Chuck Close

Michael Ganschow-Green - GRC 175 Instructor
mganschow@tmcc.edu | 673-8200 ext.5-2173

User avatar
zelouzelou
Posts: 63
Joined: Mon Aug 29, 2011 7:22 pm

Re: class id class id ???

Post by zelouzelou »

ohh I think I need to play with them more.

thanks Michael :D
Kathyleen Bullard

User avatar
Ravana
Posts: 83
Joined: Mon Aug 29, 2011 7:20 pm
Location: The Metaverse

Re: class id class id ???

Post by Ravana »

Instructor wrote:
zelouzelou wrote:Hmmm interesting. So is it kind of like if I wanted to style just one specific sentence within a webpage, I might use an id, whereas if I have a whole bunch of sentences scattered throughout the webpage that I want to style the same way, I might use a class and style it all at once?

Thanks Kyle!
Yes and no. Both instances you're describing would probably best be filled by class styles. IDs typically are used for things like div tags and images. You might use an ID targeting a particular div to style the type within it, though.

I always think of class styles as precision instruments, use for a letter, a word, or line of type, or maybe a single image or div tag. IDs and particularly tag styles are blunt instruments that require less interaction, but give less control.
Not to challenge the instructor or anything, but personally, I look at them differently (IDs and classes); in fact, the exact opposite. To me, IDs are precision instruments which you would use on one thing and one thing only, whereas classes are for styling a bunch of things, and therefore more widely used. I think maybe the difference in our line of thought is looking at it from an amount of content perspective vs. a number of elements perspective? /shrug In the end, it doesn't much matter as you'll get your styles to work either way. :)
This post has been brought to you by the letter X, the number 5, and Larry Rubald.
"It's irony at a base level, but I like it." ~Bill Hicks

User avatar
Lundholm
Posts: 205
Joined: Mon Aug 29, 2011 5:18 pm
Location: Reno NV
Contact:

Re: class id class id ???

Post by Lundholm »

An id can only be assigned to one thing on a page. A class can be assigned to more than one thing on a page.
So if you want to assign a CSS value to more than one thing on your page, for example there's TWO things you want to assign width:45px to, it might be better to assign them to a class and assign width:45px to that class. But if only one thing on each page has a certain css value, then it's always better to use an id, though even then sometimes I use a class so that I can add something to that class later if it helps my layout.
Does that make sense?
I've been told in the past that sometimes my explanations are confusing. If so I'm sorry.
- Nathan Lundholm

User avatar
Lundholm
Posts: 205
Joined: Mon Aug 29, 2011 5:18 pm
Location: Reno NV
Contact:

Re: class id class id ???

Post by Lundholm »

I think the best way to look at ID's and classes is that eventually when you learn how they work and how they differ, each designer comes up with his/her own way to use them and I don't think anyone's wrong as long as the site validates properly and looks the way it's intended to.
- Nathan Lundholm

User avatar
Instructor
Site Admin
Posts: 1869
Joined: Thu Jul 21, 2011 8:51 am

Re: class id class id ???

Post by Instructor »

Eh, there are very few "wrong" ways to use CSS. Back when I was learning CSS in the very early "oughts", I was always taught to use IDs for broad categories and then classes for fine point stuff. Looks like the theory is changing a bit from what our programming students are saying. I can definitely see the advantages of either way (automatic application vs. multi-use). It comes down to what YOU are comfortable with. Try both ways and see which you like better! :)
"Inspiration is for amateurs. The rest of us just show up and get to work." — Chuck Close

Michael Ganschow-Green - GRC 175 Instructor
mganschow@tmcc.edu | 673-8200 ext.5-2173

User avatar
Lundholm
Posts: 205
Joined: Mon Aug 29, 2011 5:18 pm
Location: Reno NV
Contact:

Re: class id class id ???

Post by Lundholm »

Yeah, my theory is that the only wrong way to use CSS is to not use it.
- Nathan Lundholm

Post Reply