nick1 Posted February 18, 2007 Share Posted February 18, 2007 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* Quote Link to comment https://forums.phpfreaks.com/topic/38982-applying-an-id-and-a-class-to-an-element/ Share on other sites More sharing options...
ToonMariner Posted February 18, 2007 Share Posted February 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/38982-applying-an-id-and-a-class-to-an-element/#findComment-187650 Share on other sites More sharing options...
ShogunWarrior Posted February 18, 2007 Share Posted February 18, 2007 It's all good, you can also add two classes like: <div class="quote joke"> ... </div> This div will now be styled by both the class quote and the class joke. Quote Link to comment https://forums.phpfreaks.com/topic/38982-applying-an-id-and-a-class-to-an-element/#findComment-187669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.