Home > Tutorial > IDs and Classes for Beginners
IDs and Classes for Beginners
Posted on Wednesday, November 24, 2010 by android apps market for tablests
Initially, I wrote this on another tutorial. But I think it is generic enough to be on its own post. This is a non-technical explanation about IDs and classes made execlusively for beginners. Here I am copying and pasting what I wrote on one of my other posts.
When it comes to styling a Blogger element using CSS (or other languages/stylesheets), things will be much easier if we know its ID or class. Why is it important for us to know an element's ID and class? Well, consider this analogy. If a person has no name, it will be difficult for us to communicate with this person. Same applies here. Just like we have names, elements have IDs and classes (some poorly constructed ones don't have any, so it'd be difficult to apply changes on them). There isn't much difference between IDs and classes. Both are used to address elements in your page. You specify an ID to an element that occurs ONLY once in your page. Whereas you can use a class to address elements that occur frequently. In short, ID = one unique element, Class = a group of elements.When it comes to CSS, you address an ID by using a hash (prefix), whereas when you address a class, you use a dot (.) prefix.
The following image shows an example of an ID. See how each gadget on the sidebar has it's own ID? They have classes as well, so you can address them by their classes too, but that's not my point here. My point is, if I use a CSS code with the ID 'Label1', only one gadget will get affected. Because there is only one gadget with ID Label1.
Consider this image now. This is a class for blog posts. See how the class 'date-outer' is being repeated several times? This is because a class can be used to address few elements. If I use a CSS code to address the class 'date-outer', 5 elements will get affected (in this particular example).
Commonly asked questions:
1) I know what is an ID and what is a class. Do I have to give my element an ID or a class now?
No, you don't have to. That is not the point of this post. You don't give names to people. You find out what their names are. The purpose of this post is for you to understand what is an ID and what is a class. And yes, it is possible for you to give an element an ID or a class using HTML if it does not already have one, but that is for another day for me to cover.
2) Some elements have IDs, some have classes, some have both! What's the big deal??
There are four types of elements. Those that have both IDs and classes, those that have IDs only, those that have classes only, and those that have neither.
3) When do you address an element using an ID?
Use an ID if you want to address only ONE particular element (that is if the element has an ID at all).
4) When do you address an element using a class?
Use a class if you want to address a group of elements.
Click here for a tutorial on how you can identify your element's ID or Class.
Click here for an example of CSS styling using an element's ID.
Click here for an example of CSS styling using an element's Class.
Have fun.
The following image shows an example of an ID. See how each gadget on the sidebar has it's own ID? They have classes as well, so you can address them by their classes too, but that's not my point here. My point is, if I use a CSS code with the ID 'Label1', only one gadget will get affected. Because there is only one gadget with ID Label1.
Consider this image now. This is a class for blog posts. See how the class 'date-outer' is being repeated several times? This is because a class can be used to address few elements. If I use a CSS code to address the class 'date-outer', 5 elements will get affected (in this particular example).
Commonly asked questions:
1) I know what is an ID and what is a class. Do I have to give my element an ID or a class now?
No, you don't have to. That is not the point of this post. You don't give names to people. You find out what their names are. The purpose of this post is for you to understand what is an ID and what is a class. And yes, it is possible for you to give an element an ID or a class using HTML if it does not already have one, but that is for another day for me to cover.
2) Some elements have IDs, some have classes, some have both! What's the big deal??
There are four types of elements. Those that have both IDs and classes, those that have IDs only, those that have classes only, and those that have neither.
3) When do you address an element using an ID?
Use an ID if you want to address only ONE particular element (that is if the element has an ID at all).
4) When do you address an element using a class?
Use a class if you want to address a group of elements.
Click here for a tutorial on how you can identify your element's ID or Class.
Click here for an example of CSS styling using an element's ID.
Click here for an example of CSS styling using an element's Class.
Have fun.
Category Article Tutorial
Powered by Blogger.
Blog Archive
-
▼
2010
(1682)
-
▼
November
(197)
- Info Product "T-Mobile Comet " 3G HSDPA Android P...
- Full Info Specification "Samsung A667 Evergreen" 3...
- Video: How To Hotpot
- Adding Buttons to Blogger Header
- Info Specification "Motorola MOTO MT716" Android S...
- New Info Product "Nexian Sound Box(Nexian NX-G509)...
- Namesake
- When Nature Pays A Visit
- iTunes won't backup iPad when syncing
- Info Specification about "Nokia C2-01" Handphone M...
- Info Specification Product "LG GS390 Prime" 3.0 in...
- No sound in apps since iOS 4.2 update
- Spirits for iPad
- How to Fix iPad No 3G service after 4.2 upgrade
- UNLOCKED DELL STREAK�S WITH NEW COLOR CHOICE AND ...
- APPLE IPAD ACASE SLIMLINE PREMIUM LEATHER CASE FOR...
- FUJITSU DISPLAYS A NEVER BEFORE SEEN 10-INCH WINDO...
- ACER UNVEILS SLIM AMD BASED WINDOWS 7 10-INCH TABL...
- ASUS U36 ULTRATHIN NOTEBOOK WITH CORE I3 & I5 13.3...
- iPad 2nd generation brings new features
- NETBOOK COMPAQ MINI CQ10-405DX AND CQ10-525DX
- TOP 10 BLACK FRIDAY WEB HOSTING DEALS
- Blogger Floating Footer
- T-mobile BOGO Promotion Now Begin
- Christmas Countdown Gadget
- How to get screen rotate lock switch back iPad iOS...
- Mail app crashes routinely on iOS 4.2.1
- iPad battery drains in sleep mode on iOS4.2
- iPad Notes only in landscape mode after upgrading ...
- Info Specification Product "T-Mobile Vibe E200" Ch...
- IOS 4.2 DIRECT DOWNLOAD LINKS LIST
- SONY PLAYSTATION PHONE SPECIFICATION
- Open Blogger Links in New Tabs
- How I�m Using Hotpot to Plan My Thanksgiving Weekend
- AirPrint - No Mail Print Icon but Safari and Photo...
- How to delete Game Center from iPad?
- MobileMe Account not verified with Find my iPad
- Product Info Specification Android Smartphone "Mot...
- Map Your Favorite Places Along the Macy�s Parade R...
- IDs and Classes for Beginners
- Remove Space between Blogger Posts
- Remove Space between Gadgets in Blogger Sidebar
- iPad stuck on cancelling sync
- AirPrint Setup on the iPad
- Most-Rated Google Places
- We Have Gone to SouthernSpeakers.net
- Music, Videos lost after iPad updated to iOS 4.2
- How Many iPad Apps and Folders Can I Have?
- How to Use AirPlay For Videos, Photos and Music
- Big Bad Sudoku Book - Game Center game
- iOS 4.2 AirPrint compatible printers
- iPad mute switch doesn't mute on iOS 4.2.1
- Lunch is on Google
- NEW TABLET ANDROID TOSHIBA FOLIO 100
- Siemens GreenTouchscreen� - Higher Education
- Nokia World's first ice touchscreen virtually burns
- Resize Blogger Post Image
- Update Apps Before updating to iOS 4.2 for iPad
- Trucks and Skulls HD
- iTunes Connect Mobile for iPad
- T-mobile 's "4G Sweepstakes" Contest
- HTC Released myTouch 4G Source Code
- Christmas Tale for iPad
- iPad crashes when scrolled through photos in iPhotos
- Hotpot's First Week
- Remove Blogger Static Page Titles
- How to get started with Game Center on iPad
- iOS 4.2 for iPad Release Date Delayed Again
- Info New Produk With Great Specs "LG L-03C" 12MP C...
- InFo Complete Specification Product "LG C320 InTou...
- Upload Multiple Pictures with Blogger's Updated Ed...
- Reposition Blogger Header Image
- Google Sky Map- now with time travel
- Google Sky Map- now with time travel
- Talking Gremlin HD - Entertainment app
- Running android OS on your iPad
- How to add PDF files to iBooks & read them on your...
- Info Complete Specification "Sony Ericsson Xperia...
- Information Product Specification CDMA Android Pho...
- AmazonWireless myTouch 4G Now Only $49 on Backordered
- Latest myTouch 4G Ad - Still Hits AT&T
- Editing your Google Docs on the go
- Editing your Google Docs on the go
- Info Product Specification "Samsung Nexus S (Samsu...
- review "ZTE Peel" Change Ipod Touch Into Iphone
- Introducing the Hotpot Blog
- Google Voice for iPhone
- Google Voice for iPhone
- Offline, meet online: a marketing experiment with ...
- Offline, meet online: a marketing experiment with ...
- Should I Upgrade iPad to iOS 4.2?
- EyeTV Enables Satellite TV on iPad running iOS 4.2
- Can't stop Mail checking email on iPad
- Android 2.3 Gingerbread Features
- Eric Schmidt teases Nexus S with Gingerbread
- Personally Yours on the Go - Personalized Recommen...
- Personally Yours on the Go - Personalized Recommen...
- Complete Info Specification of Android Phone "Dell...
- Review LG 4G Modem and Pantech UML290 VL600 4G W...
- Google Shopper 1.3 adds search filters and feature...
-
▼
November
(197)


