- My Forums
- Tiger Rant
- LSU Recruiting
- SEC Rant
- Saints Talk
- Pelicans Talk
- More Sports Board
- Fantasy Sports
- Golf Board
- Soccer Board
- O-T Lounge
- Tech Board
- Home/Garden Board
- Outdoor Board
- Health/Fitness Board
- Movie/TV Board
- Book Board
- Music Board
- Political Talk
- Money Talk
- Fark Board
- Gaming Board
- Travel Board
- Food/Drink Board
- Ticket Exchange
- TD Help Board
Customize My Forums- View All Forums
- Show Left Links
- Topic Sort Options
- Trending Topics
- Recent Topics
- Active Topics
Started By
Message
Actual difference between css selectors id and class
Posted on 8/7/15 at 8:00 pm
Posted on 8/7/15 at 8:00 pm
I haven't messed with html/css in a long time and when I did it was pretty basic stuff.
My goal is to get through some html/css lessons, move into php and then really get into some sql.
Anyway, I'm getting way ahead of myself. I'm going through some lessons on CSS, and it's telling my that the class selector are for many html elements but the id selector is for exactly one html element. But as I play with the code a bit, it seems evident that the class and id tags are interchangeable. I can use the same id tag for any number of html elements, including applying it to the body tag and applying attributes to the whole page.
So, what, technically, is the difference between the tags? Can you show me an example of where one works and the other doesn't? Thanks.
My goal is to get through some html/css lessons, move into php and then really get into some sql.
Anyway, I'm getting way ahead of myself. I'm going through some lessons on CSS, and it's telling my that the class selector are for many html elements but the id selector is for exactly one html element. But as I play with the code a bit, it seems evident that the class and id tags are interchangeable. I can use the same id tag for any number of html elements, including applying it to the body tag and applying attributes to the whole page.
So, what, technically, is the difference between the tags? Can you show me an example of where one works and the other doesn't? Thanks.
Posted on 8/7/15 at 9:42 pm to Casty McBoozer
You *can* use duplicate ids in client html code... as in... the page will load. It's not valid html though. Any JS you write won't be able to uniquely identify any elements.
Posted on 8/7/15 at 10:07 pm to TigerRagAndrew
Posted on 8/8/15 at 8:22 am to TigerRagAndrew
What he said. Also, if you want to style the entire body, you can just use the body tag. There's no need to id nor class it since it's guaranteed to be the only one on every page.
Posted on 8/8/15 at 6:17 pm to Casty McBoozer
Unless you plan on using JS for functions selecting these elements, there's not much point in using id's for low-level work. You only use an id if you very specifically need to target a specific element, ONE time in a page. Using it more can cause problems with validation and make it hard for JS to figure out which element you are trying to use.
Popular
Back to top
Follow TigerDroppings for LSU Football News