【问题标题】:How can I style Blazor Components differently如何以不同方式设置 Blazor 组件的样式
【发布时间】:2021-03-07 23:26:44
【问题描述】:

假设我有组件<MyText />。如何根据实现的不同位置设置不同的样式?

例如,这就是我想要做的(使用引导类方便):

MyDocument.razor

<div> This text below will be red.</div>
<MyText class="text-danger" /> 

<div> This text below will be blue.</div>
<MyText class="text-info" />

这将输出以下内容

【问题讨论】:

    标签: c# css components blazor


    【解决方案1】:

    看看Attribute splatting and arbitrary parameters
    MyText.razor

    <div @attributes="AdditionalAttributes">Some Cool Text</div>
    
    @code {
     [Parameter(CaptureUnmatchedValues = true)]
     public Dictionary<string, object> AdditionalAttributes { get; set; }
    }
    

    MyDocument.razor

    <div> This text below will be red.</div>
    <MyText class="text-danger" /> 
    
    <div> This text below will be blue.</div>
    <MyText class="text-info" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多