- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.7k
Closed as not planned
Description
Describe the problem
Hey everyone,
Sometimes you need to modify the (S)CSS of an existing component without editing its source file. To do that, you typically use the :global selector, which allows you to apply styles to class names that are outside the scope of the current component or page.
However, I find that approach inconvenient. If you like keeping things clean and don’t want to use inline styles or, for example, need to use @media queries you’d have to wrap the component in a div and write something like:
<script>
  import MyComponent from "./Component.svelte"
</script>
<div class="sample">
  <MyComponent class="sample-component"/>
</div>
<style lang="scss">
  .sample {
    display: contents;
    :global(.sample-component) {
      /* styles */
      @media (max-width: 1000px) {
        /* styles */
      }
    }
  }
</style>That ends up being unnecessary boilerplate code.
Describe the proposed solution
My suggestion is to add a :component selector, which would allow you to do the following:
<script>
  import MyComponent from "./Component.svelte"
</script>
<MyComponent />
<style lang="scss">
  :component(MyComponent) {
    /* styles */
    @media (max-width: 1000px) {
      /* styles */
    }
  }
</style>Importance
would make my life easier
Metadata
Metadata
Assignees
Labels
No labels