Reputation: 101
Is it valid to name divs like this?
<div class="frame header">Some content here</div>
With a space in the name? Then, of course, in the css I would have something like:
.frame { display: block; }
.header { background-color: #efefef; }
I guess I'm just wondering if you can have a space in the actual markup like I posted and it be XHTML strict? I've checked on the W3C validation, but for some reason, anything I put in there is passing. Sigh...
Upvotes: 1
Views: 304
Reputation: 779
What you are doing is valid.
However, any number of <div>
elements in an html/xhtml document can have the same class definitions for presentation purposes.
Since the name
attribute has been replaced with id
attribute in xhtml, it is always better to have an ID
attribute to uniquely name and reference a particular element.
Upvotes: 0
Reputation: 54729
Yes, you can. The class is not really a 'name' for the element, but a list of classes that apply to it, separated by spaces. If you want that element to have a specific 'name' that pertains only to it, use the id
attribute. Remember that is has to be completely unique in the document, and also that ID's cannot have spaces.
Something like:
<div class="frame" id="header">Some content here</div>
.frame { display: block; }
#header { background-color: #efefef; }
Upvotes: 1
Reputation: 94101
ids and classes can't have spaces. If you put a space then you're adding two classes, so W3 is interpreting that as it is and won't throw you an error. Your css is correct.
Upvotes: 2