Jump to content

Applying an id AND a class to an element


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.