Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<span>/<div> shorthand for css - is this legit?

Tags:

html

css

If I create an HTML element:

sc {
    font-variant: small-caps;
}

and apply it like this:

I want to display <sc>this text</sc> in small-caps.

it works as expected (except in IE, of course.) It becomes shorthand for

.sc {
    font-variant: small-caps;
}
I want to display <span class='sc'>this text</span> in small-caps.

Is this intended/documented behavior? Is there a name for it?

like image 387
dkretz Avatar asked May 31 '11 17:05

dkretz


1 Answers

XHTML (and XML on which it is based) is designed to let you add custom elements in a similar fashion, but instead using a custom XML namespace with your element names. Then you can either use CSS to style those elements directly, or use XSLT to transform them into real HTML elements. This is why (or at least one reason why) standards-compliant browsers are OK handling otherwise non-standard elements in the DOM.

In HTML 4 and older, it's always invalid to sprinkle your own non-standard elements on (not sure about HTML5's extensibility).

Either way, however, IE doesn't automatically know about the custom elements in the DOM, so you need to use document.createElement() to create them before the DOM finishes loading.

like image 59
BoltClock Avatar answered Sep 24 '22 02:09

BoltClock