I put together a jQuery plugin that changes the aspect of the text in an HTML container and gives it an LCD-like appearance. Each character converted by the plugin is constructed with several square blocks (“bricks” as I’ve called them), absolutely positioned in a parent container – one container for each character converted. The bricks are in fact <b> tags with a display: block rule applied to them.
I’ve used them instead of <div> in order to reduce the amount of markup, but I want to know if there are downsides to this approach that I’m not aware of.
You can see the plugin in action here: Digitize
It makes little difference, but perhaps a
divorspanwould be more appropriate due to their lack of semantic meaning.You aren’t saving much here as the markup is built dynamically, so the length difference between
banddivorspanisn’t significant in any way.The HTML spec says:
But on the other hand, it really makes no difference when producing it using JS other than neatness. Twitter bootstrap horribly uses
ifor icons for instance!The ‘correct’ way to do this by the way is to use the Shadow DOM – it’s pretty brandspanking new, but it allows you to hide away implementation details in the same way that a
selecttag does (i.e. html just hasselectandoptionelements, but behind the scenes there is more going on).For a demo, check out http://adobe.github.com/web-platform/samples/css-regions/shadow-dom/ in a new browser. If you use Chrome, then turn on Developer Tools Experiments in
chrome://flags/, then in the inspector menu turn on the View Shadow DOM option. This will let you see what’s happening here.In short, you can make elements that are isolated from everything else and essentially invisible. You can style them as per usual, but can also isolate them from the rest of the CSS. They behave just like regular ones, except that they are not addressable in the normal way.
If I were making this plugin, I’d use Shadow Dom where I could, with a fallback to
spanorbor whatever, mainly just because cool stuff is cool!