Scoped Stylesheet -vs- CSS Hierarchies

Status of scoped stylesheets

Since their initial introduction, Scoped Stylesheets did not gain much traction among Web developpers. The most important problem of scoped stylesheets is that they have a big compatibility issue: they are honored as global stylesheets in browsers that don't support them, and that virtuallly includes all of them at this time.

Another problem is that they tend to promote a bad design pattern in which formatting is nested inside semantic content. While inline formatting is not to reject for small, one-shot style adjustements, using the <style> tag (and even the style attribute) in production has become less and less mainstream over time.

My call to action would be to remove the scoped stylesheet from the HTML5 specification and rely on new CSS proposals like CSS Hierarchies to provide similar features.

We can do better

Based on the fact the objective of scoped stylesheets is to apply 'local' styling, I think it's probably a better solution to extend the style attribute to accept new input, namely anything that can be found in a regular CSS rule, including concepts introduced by CSS Hierarchies.

CSS Hierarchies in action

a.hiddenLink {
    color: inherit; text-decoration: none;
    &:hover {
        color: blue; text-decoration: underline;
    }
}

article {
    padding: 20px;
    & h1 { margin-top: 0.5px; }
}

In the style attribute

<a class="hiddenLink" style="color: blue; &:hover { color: red; }">
    I'm a link who doesn't follow the traditionnal look and feel of links in the site.
</a>

<article style="& h1 { margin-top: 0px; }">...</article>

Why is it better?

This is better for many reasons:

1] Browsers that don't support CSS Hierarchies in the style tag will properly ignore the new style declaration (beside IE6 which has a bug in the way he parse the style tag).

2] Because developers tend to avoid multiline style attributes, this prevents them to have them write long local stylesheets that are contrary to the "Styling and content independance" design pattern, while giving the possibility to do so when they are requied (AJAX loading, ...).

3] It keeps the symmetry between the style attribute and the CSS rule syntaxes. Indeed, if we're going to make it possible to write nested sub-rules inside traditionnal CSS rules, there'll be pressure to enable them in the style attribute as well, and it would be logical to do so. If we do that, there'll be no need for scoped stylesheets anymore.

4] This removes the problem of @fontface / @keyframe rules that are implemented globally by browsers and can't be used properly in a scoped stylesheet. Because you can't use them as nested rules inside a CSS rule, you'll not be able to use them in a scoped style attribute either.

Call to action

1] Remove the scoped attribute from the HTML5 specification and recommands support of CSS Hierarchies instead.

2] Modify the CSS Style Attribute specification to introduce a new cascade level between "document" and "!important" that would host rules defined by the style attribute.

3] If you agree with me but can't do any of the above, maybe could you just spread the word using social media, maybe you'll end up by reaching someone else who can ;-)

Regards,
François REMY

Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :
Publié 07 mars 12 03:01 par FREMYCOMPANY
Classé sous : , ,

Commentaires

Pas de commentaires
Les commentaires anonymes sont désactivés

About FREMYCOMPANY

François REMY est un jeune développeur belge plein d'entrain qui traite surtout des technologies du web et de DotNet dans ses articles.


Les 10 derniers blogs postés

- Office 365: Nettoyage des versions de List Item avant migration depuis SharePoint On Premise vers SharePoint Online par Blog Technique de Romelard Fabrice le 08-08-2017, 15:36

- Office 365: Comment supprimer des éléments de liste SharePoint Online via PowerShell par Blog Technique de Romelard Fabrice le 07-26-2017, 17:09

- Nouveau blog http://bugshunter.net par Blog de Jérémy Jeanson le 07-01-2017, 16:56

- Office 365: Script PowerShell pour assigner des droits Full Control à un groupe défini par Blog Technique de Romelard Fabrice le 04-30-2017, 09:22

- SharePoint 20XX: Script PowerShell pour exporter en CSV toutes les listes d’une ferme pour auditer le contenu avant migration par Blog Technique de Romelard Fabrice le 03-28-2017, 17:53

- Les pièges de l’installation de Visual Studio 2017 par Blog de Jérémy Jeanson le 03-24-2017, 13:05

- UWP or not UWP sur Visual Studio 2015 ? par Blog de Jérémy Jeanson le 03-08-2017, 19:12

- Désinstallation de .net Core RC1 Update 1 ou SDK de Core 1 Preview 2 par Blog de Jérémy Jeanson le 03-07-2017, 19:29

- Office 365: Ajouter un utilisateur ou groupe dans la liste des Site collection Administrator d’un site SharePoint Online via PowerShell et CSOM par Blog Technique de Romelard Fabrice le 02-24-2017, 18:52

- Office 365: Comment créer une document library qui utilise les ContentTypeHub avec PowerShell et CSOM par Blog Technique de Romelard Fabrice le 02-22-2017, 17:06




Search

Go

Ce blog

Abonnements