As an addition to @user774031 answer:
Blazor Framework Adds an Id to Isolated css class to make them scoped to Razor component but since this Id attribute added on Runtime, they do not add to child InputComponent and so the css class defined using css isolation do not apply and we should define them globally. To make them work as isolated css class define them as below for example:
1- Define a .Net class which inherit from FieldCssClassProvider and override its GetFieldCssClass method. This method should
return some string as classname from editcontext and fieldIdentifier object.
public class MyCustomeCSSProvider : FieldCssClassProvider
{
public override string GetFieldCssClass(EditContext editContext, in FieldIdentifier fieldIdentifier)
{
string className = string.Empty;
if (editContext.IsModified(fieldIdentifier))
{
className += " modifiedField";
}
if (editContext.GetValidationMessages(fieldIdentifier).Any())
{
className += " invalidField";
}
else
{
className += " validField";
}
return className;
}
}
2- in OnInitialized life cycle Set CssClassProvider for edit context using extension method:
_context = new EditContext(student);
_context.SetFieldCssClassProvider(new MyCustomeCSSProvider());
3- Define your class in isolated css files as below using ::deep :
::deep .validField {
border-color: lawngreen;
}
::deep .invalidField {
background-color: tomato;
}
::deep .modifiedField {
border: yellow dashed 2px;
}