Overwrite child components CCS with scoped styles (feature)
See original GitHub issueA Parent component should have the ability to overwrite a child components style when both components only have scoped
styles.
Currently there is no way to overwrite a child components css style with scoped styling.
Angular2 has a selecor called /deep/
, It would be nice to have a similar feature in Vue
Component styles normally apply only to the HTML in the component's own template.
We can use the /deep/ selector to force a style down through the child component tree into all the child component views. The /deep/ selector works to any depth of nested components, and it applies both to the view children and the content children of the component.
In this example, we target all <h3> elements, from the host element down through this component to all of its child elements in the DOM:
COPY CODE
:host /deep/ h3 {
font-style: italic;
}
The /deep/ selector also has the alias >>>. We can use either of the two interchangeably.
The /deep/ and >>> selectors should only be used with emulated view encapsulation. This is the default and it is what we use most of the time. See the Controlling View Encapsulation section for more details.
https://angular.io/docs/ts/latest/guide/component-styles.html#!#sts=%2Fdeep%2F
Issue Analytics
- State:
- Created 7 years ago
- Reactions:44
- Comments:13 (7 by maintainers)
Top Results From Across the Web
How to override scoped styles in Vue components?
This easily overrides the scoped rules in CompB. Parent overrides. For situations where I want to override both the global and scoped rules....
Read more >Overriding Child Component Styles — The Right Way
Overriding Child Component Styles — The Right Way ... Scoped CSS is fantastic for keeping things tidy, and not accidentally bleeding styles into...
Read more >Scoped CSS - Vue Loader
With scoped , the parent component's styles will not leak into child components. However, a child component's root node will be affected by...
Read more >how to change the style of scoped child components-Vue.js
[Solved]-Vue: how to change the style of scoped child components-Vue.js ... Use ::v-deep in this case, as /deep/ will get deprecated. ... Just...
Read more >How to Use Vue CSS Variables - Reactive Styles RFC
The Single File Component Styles RFC gives us Vue developers a way to use a component's reactive data as CSS variables.
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
Here is a working example that I put together from our existing websites functionality converted to Vue components. I used a Global Style on the Root component which did not work.
https://gist.github.com/agaripian/7b430d1ffa3b360c4709010e7013675c
Profile
>followButton
>button
Button
andfollowButton
have scoped styles.Profile
uses Global styles to overwrite childrenfollowButton
overwritesbutton
styles.Profile
can not overwritebutton's
background color.Can not overwrite background color
Angular2 with
/deep/
adds the unique ID attribute selector from component that is using/deep/
. I manually added the the unique id attribute ofProfile
to its style selector and it solved the problem as well as scoped it properly. It also automatically makes the selector more specific so we can avoid !important. (see blue highlight below)I want to avoid using Global styles so we can truly scope our css. I can probably find another way of adding some more specific css selector but that just complicates development and debugging.
Lets take the
menu > menuItem
example. Menu has a list of child menuItem components. See the below code snippet.Now if you have 2 different components that use menu-item components on the page and you want to style the menu-items differently on the page.
Using global styles (not scoped) in the menu component (parent) will also change the style of the 2nd menu item on the page unless some other unique identifier is used to scope the styles.
Nothing is stopping me from using BEM, but why use it when there are scoped styles that can solve the problem.