question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improved parent selector support for :host ?

See original GitHub issue

https://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:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
seven-phases-maxcommented, Nov 7, 2017

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)

0reactions
stale[bot]commented, Mar 14, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found