-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support fragment references in the <link>
tag's href
attribute
#11019
Comments
sheet
attribute to the <link>
tag's for CSS @sheet
support<link>
tag's href
attribute
This feature could tie neatly into "declarative adopted stylesheets" (as an alternative to #10673). Since the whole purpose of adopted stylesheets is to reference the original stylesheet instance, it makes sense to me that a Example code using a new <style id="inline_styles">
p { color: blue; }
</style>
<p>Outside Shadow DOM</p>
<template shadowrootmode="open">
- <link rel="stylesheet" href="#inline_styles">
+ <link rel="adopted-stylesheet" href="#inline_styles">
<p>Inside Shadow DOM</p>
</template> (This would prepopulate Keeping in mind that the "constructed" limitation on adopted stylesheets is likely going to be lifted (w3c/csswg-drafts#10013), does this sound feasible? Using adopted stylesheets would be more performant and also avoid some of the harder questions such as "what happens when the original stylesheet contents change?" (changes propagate automatically). This does not yet solve the problem of wanting to "disable" a stylesheet in light DOM, but that's a slightly different use-case, and |
Can someone remind me why the I also don't think it's a good idea to mix URLs and same-document references due to base URLs and such. It's rather messy. |
@annevk - do you mean duplicating
I agree that base URL's add some complexity here. This is a great call out. I can think of a few ways to solve this. One option is to use a different attribute than |
@mayank99, this could be another good option. I have a few thoughts here:
|
When would a base element cause a need in the first place to disambiguate an existing URL use case from a (now-unsupported) reference to a document element? <base href="http://a-url/" />
<style id="inline_styles">
/* ... */
</style>
<!-- ... -->
<link rel="stylesheet" href="#inline_styles" /> now just produces an error: Refused to apply style from 'http://a-url/#inline_styles'
because its MIME type ('text/html') is not a supported
stylesheet MIME type, and strict MIME checking is enabled. If there is a need to disambiguate an element reference, perhaps a new link type attribute, say like "element"?: <link rel="stylesheet element" href="#inline_styles" /> |
I don't think this can work with a new An alternate proposal for this could be to use a new URL scheme, similar to <style id="root-bundle">...</style>
<link rel=stylesheet href="element:root-bundle">
<my-element>
<template shadowrootmode=open>
<style id=inner-theme>...</style>
<link rel=stylesheet="element:/root-bundle">
<!-- or -->
<link rel=stylesheet="element:../root-bundle">
<link rel=stylesheet="element:inner-theme">
</template>
</my-element> Regarding mutability, I think this should work the same way as links and imports today and not change their semantics - once the URL is imported, it's immutable and doesn't track changes. To have an imported thing that tracks changes is something that needs to be done with JS, as it's done today. |
What is the issue with the HTML Standard?
The problem
There are currently several options for sharing styles with Declarative Shadow DOM, but all of them rely on external files or dataURI's:
<link rel="stylesheet" href="foo.css">
this requires an external file.<link rel="stylesheet" href="data:text/css;...">
this is not technically an inline style definition, but it doesn't generate a network request, so it's as close as you can get to an inline style today. This must be re-parsed and duplicated in memory for each instance, and the dataURI syntax has poor developer ergonomics.adoptedStyleSheets
via Javascript - using Javascript somewhat defeats the purpose of Declarative Shadow DOM, and this approach still only supports entire files (or a dataURI).Use cases
@sheet
- this will enable CSS@sheet
to work with inline CSS. CSS@sheet
will only work in external CSS files unless there's a mechanism for referencing inline style blocks as mentioned in this proposal. For more details (including examples), see this @sheet explainer.Proposed Solution
Allow the
<link>
tag'shref
attribute to support same-document references to corresponding fragment identifiers for<style>
tags.Prior Art
xlink:href
syntax is very similar, although it allows cross-document references. For HTML, this might not be desirable.The text was updated successfully, but these errors were encountered: