The tricky thing about CSS isolation is that it works with plain HTML nodes only, it does not work for components. Under the covers, the elements from your current component that defines isolated CSS get a custom (kind of random) attribute, and CSS rules cascade through that to get scoped to your current component. The framework does not know what is inside other components, through, so it cannot add that attribute to them - their rendering is their own. So, these scoped CSS rules cannot target components.
How to work around that - wrap your components in an HTML element from your current component and write your rules to target elements inside that container too by replacing that element with ::deep
.
Here's an example:
input,
::deep input{
display: block;
border: 2px solid red;
}
p,
::deep p {
color: lime;
border: 2px solid red;
}
And here's how to modify the form
<EditForm Model=SomeModel>
<div> @* This div right here is the "magic" *@
<InputText @bind-Value=SomeModel.Property1 />
<InputText @bind-Value=SomeModel.Property2 />
<p>a paragraph</p>
</div>
</EditForm>
@code{
TestModel SomeModel { get; set; } = new TestModel();
public class TestModel
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…