- This topic is empty.
-
AuthorPosts
-
July 2, 2012 at 10:35 pm #38745
Steven_Domanico
MemberI have an argument with my colleague here, on whether to use ID’s (currently in this sample) or classes, inside this HEADER portion of HTML. Of course, all the items are unique and won’t appear on the same page more then once. What would you say?
July 2, 2012 at 10:52 pm #105272Senff
ParticipantTechnically, if they’re all unique, it doesn’t matter. Semantically, maybe a little. For example, you could give both menus the class “menu”, and then one has ID “main-menu” and the other “additional-menu”.
In essence, if there are elements on the page that share some properties, then bundle those properties in a class and assign that class to those elements.
But if the look/functionality/structure of all those elements is all unique anyway, go ahead and use IDs as much as you want, I guess.July 3, 2012 at 9:12 am #105289Schmotty
ParticipantID is used to define a single object on the page. Class is for classifying certain objects. (is this too technical? I feel like a know-it-all).
Myself, I use ID mostly as a js selector, but I will style by id when I have one. But really if you have a single object on a page with a certain purpose like “main-menu” that could have a unique ID. It could also have a class of “menu”. say you want all your menu links to be the same color but the main menu is sized differently:
#main-menu {
width:100%;
height:60px;
}
.menu a {color:red;}
July 3, 2012 at 10:47 am #105301wolfcry911
ParticipantWhy so many divs in the first place? I agree with the others, the menus may warrant a class – then again they can both be addressed with th descendant selector #header ul anyway. I’d clean it up a bit:
And depending on the desired look, I may combine the menus into one.
July 3, 2012 at 1:14 pm #58695TheDoc
MemberI’m not 100% sure on this, but if you end up using some sort of JS on the page I think jQuery is a tiny bit quicker when looking for IDs over classes. I could be wrong here and it most cases it wouldn’t matter (since the speed difference would be incomprehensible to most people) but it’s something to consider if you were building a massive form.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.