You should to learn about "Component Parameters": [Parameter]
. On your component, declare a parameter:
<div class="container @CssClass">
"some nested content"
</div>
@code
{
[Parameter] public string CssClass {get; set;} = "";
}
Now, when you use your component, if you want, you can set a value to the parameter:
<MyComponent CssClass="new-class" />
Quoting docs:
Components can have component parameters, which are defined using public simple or complex properties on the component class with the [Parameter] attribute. Use attributes to specify arguments for a component in markup.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…