You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge-base/common-css-isolation.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,4 +70,40 @@ The problem is that this applies only to plain HTML elements, but it does not ap
70
70
71
71
## Solution
72
72
73
-
Use CSS rules that are global to the application and not scoped to a particular component through the CSS Isolation feature. You can also use the `Class` parameter of the Telerik components to cascade through it if you want to target particular instances only.
73
+
There are two ways to go around this:
74
+
75
+
* Use CSS rules that are global to the application and not scoped to a particular component through the CSS Isolation feature. You can also use the `Class` parameter of the Telerik components to cascade through it if you want to target particular instances only.
76
+
77
+
* Use the `::deep` pseudoselector that the framework translates to the random identifier attribute it adds to the DOM in the scoped selectors, and wrap nested components in HTML elements such as `<span>` or `<div>`
78
+
79
+
>caption Sample CSS selector that uses `::deep` to cascade for nested components
80
+
81
+
````CSS
82
+
.my-component-button-class,
83
+
::deep .my-component-button-class {
84
+
font-size: 20px!important;
85
+
}
86
+
````
87
+
88
+
>caption Sample way to wrap nested components in HTML elements from the current component so `::deep` rules can affect them
89
+
90
+
````CSHTML
91
+
<p>This button's class is defined in the component's scoped css file. It's applied to the wrapping element from this component (a span in this case, make sure to use an appropriate one to have valid HTML) and the ::deep pseudoselector applies it to the button.</p>
92
+
<span>
93
+
<TelerikButton Class="my-component-button-class"
94
+
Primary="true">
95
+
The font size should be larger but the scoped class is not applied properly.
96
+
</TelerikButton>
97
+
</span>
98
+
99
+
<p>Custom component nesting has the same behavior - elements from child components do not get the CSS isolation attribute but you can also cascade through some HTML element</p>
<p>This html successfully takes the class defined in the scoped css file because it is plain HTML on the component that defines the custom CSS rule.</p>
105
+
<button class="my-component-button-class">
106
+
The font size is larger thanks to the scoped css file.
0 commit comments