Replies: 1 comment
-
Yes, or at least support targeting the component's root element(s) using :scope, e.g.
This would avoid the need to use arbitrary class names to target the root element, which I personally encounter frequently. A similar proposal has been discussed here: vuejs/vue-loader#1601 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, scoped CSS is done by compiler.
However, today's CSS has great @scope rule.
By using this, I think we can achieve CSS scoping even more simply.
Example 1
Currently, if include
<style>
inside<template>
it will be ignored, but if only@scope
exists it will be passed through.<!-- Good --> <template> <style> @scope { .foo { background-color: cyan; } } </style> <div class="foo">Scoped</div> </template> <!-- Bad, ignored --> <template> <style> .foo { background-color: cyan; } </style> <div class="foo">Scoped</div> </template>
Example 2
Add
.css
or.style
to component object.Write your CSS rules inside it.
It's debatable whether to explicitly state
@scope
or add it internally.Then insert contents of
.css/.style
directly under template root.I don't know details of how template engine works internally, but I think it goes something like this.
Both will eventually be inserted into template.
Note
According to Can I Use FireFox is only modern browser that doesn't support
@scope
, but they are currently working on adding feature.Beta Was this translation helpful? Give feedback.
All reactions