Jump to content

Applying an id AND a class to an element


nick1

Recommended Posts

Greetings,

 

While working on some CSS tonight, I had one of those "what the heck, why not" moments.  I applied an ID and a CLASS to a DIV to see if the DIV would take on both rule sets.  I didn't expect this to work since I never tried it before.  But to my surprise, it worked:

 

<div class="component" id="operatingsystem" >

blah blah blah blah blah

</div>

 

I apologize if I'm showing my "newbieness" to CSS.

Now my question:  is this considered 100% valid markup?

It definitely reduced a whole bunch of redundant markup for me.

I'm just hoping my technique is considered valid.

 

Thanks,

 

*Nick*

Link to comment
https://forums.phpfreaks.com/topic/38982-applying-an-id-and-a-class-to-an-element/
Share on other sites

It's a valid as the hills are old.....

 

If fact that is the way to do stuff - its what class and id were made for.

 

Remeber though you can only use an id once on a page - its not valid to have two elements (ie. two divs) with the same id. This won't stop most browsers from displaying what you want or breaking (IMO it shoudl break though!) but any javascript that works on the content will fail as will html validation.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.