Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Semantic way for loading styles #69

Closed
FagnerMartinsBrack opened this issue Sep 25, 2014 · 5 comments
Closed

Semantic way for loading styles #69

FagnerMartinsBrack opened this issue Sep 25, 2014 · 5 comments

Comments

@FagnerMartinsBrack
Copy link
Contributor

The spec does not allow <style> tags inside other element than the <head> element.
The following elements can be used inside a <head>: <title>, <base>, <link>, <style>, <meta>, <script>, <noscript>, <command>.

I can't declare style tags as a surface using data attributes and still keeping my document spec compliant, because I can't add id="style" and id="style-default" elements into the document's head.

What is the recommended practice for loading styles using senna?

@FagnerMartinsBrack FagnerMartinsBrack changed the title Semantic way for loading style tag surfaces Semantic way for loading styles Sep 25, 2014
@eduardolundgren
Copy link
Contributor

The reason it doesn't work is because senna data attributes handler uses document.body as base element, see https://github.com/eduardolundgren/senna/blob/master/src/senna.js#L368.

You can register them via JavaScript:

var app = senna.dataAttributeHandler.getApp();
app.addSurfaces('style');

This should work.

@FagnerMartinsBrack
Copy link
Contributor Author

I tried to do as you suggested, setting an id attribute in the style tag in the head and adding as a surface through plain JS, but it didn't worked for some reason.

I started debugging the code and realized when I click the link it is appending a <div id="style-screen_*"> element inside the head. Is that the correct behavior or I am doing something wrong?

Screenshots below:
image
image

@eduardolundgren
Copy link
Contributor

Well, that make sense, it appends the screen history to it. It's not possible then to do that currently.

In order to support it needs to support customizing the content element from div to something else, or even nothing.

The closest you can get for now is: Place the style inside a <div id="style"> inside <head> (which I am afraid is not valid HTML still):

<div id="style">
    <div id="style-default">
      <style>body{background: blue;}</style>
    </div>
</div>

We usually do that on the <body> anyways, but if it's not semantic we may need to think about a solution.

@FagnerMartinsBrack
Copy link
Contributor Author

We usually do that on the <body> anyways, but if it's not semantic we may need to think about a solution.

Yes, I am currently using it in the body here.

I digged a little deeper though, and it seems that according to here if the scoped attribute is present, the style tag becomes a flow content:

The scoped attribute is a boolean attribute. If present, it indicates that the styles are intended just for the subtree rooted at the style element's parent element, as opposed to the whole Document.

In this case it may be reasonable to put the style content inside the body with the scoped attribute, applying the styles in the body scope.
If there's no drawbacks, it seems to be the only semantic solution without changing senna's behavior.

@eduardolundgren
Copy link
Contributor

SGTM. Let me know how that goes and if the outcome is fine feel free to close the issue. Thank you for reporting.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants