Improved parent selector support for :host ?
See original GitHub issuehttps://developers.google.com/web/fundamentals/web-components/shadowdom#styling
It’s hard to understand how to create shared styles for native and custom elements (light vs shadow DOM)
Example:
button.less
button {
.shared-style;
}
my-custom-button.less
:host {
.shared-style;
}
…/shared/button-styles.less
.shared-style() {
&:hover {
color: red;
}
}
CSS output
button:hover {
color: red;
}
:host:hover {
color: red;
}
This is incorrect as :host
requires any other selectors to be placed inside of parentheses.
For example:
:host(:hover) {
color: red;
}
This can be fixed for :host
by doing:
.shared-style() {
&(:hover) {
color: red;
}
}
The problem is that this then breaks the button
styles which is not ideal when sharing styles between native and custom elements - it all gets a bit complicated.
Breaking up the mixin into smaller parts is an option, however, as :host
always requires parentheses, could {less} automatically output them in the CSS?
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Meet :has, A Native CSS Parent Selector (And More)
In this article, we're going to answer those questions and check out the early spec of :has selector and see how it should...
Read more >host() - CSS: Cascading Style Sheets - MDN Web Docs
The :host() CSS pseudo-class function selects the shadow host of the shadow DOM containing the CSS it is used inside (so you can...
Read more >Is parent selector available in css4? [closed] - Stack Overflow
querySelector() but not to CSS itself. This wouldn't really help you in any way, since it's already possible to find a parent element...
Read more >Parent Selectors in CSS
Jonathan says if there was a parent selector, that would then easily be the new top dog in inefficient selectors. The argument being...
Read more >Angular :host, :host-context, ::ng-deep - The Complete Guide
Angular CLI CSS Preprocessors support - Sass, Less and Stylus; How can we use Sass to improve our styles; Summary. In order to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re closing to early I think. I’d wait for other opinions (me is known to be against everything and whining the most). After all there may be some neat idea flying around that could make everybody happy 😃…
(After all such sketching for possible workarounds sometimes makes one to step into weird never-seen-yet snippets like this for example)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.