Blazor 简单组件(2):B_row/B_col 12分隔布局 简单开发

文章目录

  • 前言
  • 12分隔布局开发
    • B_col.razor
    • B_col.razor.css
    • B_row.razor
    • B_row.razor.css
  • 使用案例

前言

Blazor 简单组件(0):简单介绍

12分隔布局开发

Blazor 简单组件(2):B_row/B_col 12分隔布局 简单开发_第1张图片

B_col.razor

@if (Offset != "0")
{
    <div style=" grid-column-start: span @(Offset)">
    </div>
}

<div class="@GetClass()" style=" grid-column-start: span @Span">
    @ChildContent
</div>

@code {
    [Parameter]
    public RenderFragment ChildContent { get; set; }
    /// 
    /// 分隔个数,默认12分隔
    /// 
    [Parameter]
    public string Span { get; set; } = "12";

    /// 
    /// 向右偏移
    /// 
    [Parameter]
    public string Offset { get; set; } = "0";



    private string GetClass()
    {
        return isBorder ? "B_Col" : "";
    }

    /// 
    /// 是否启用边框,默认不启用
    /// 
    [Parameter]
    public bool isBorder { get; set; } = false;
}


B_col.razor.css

B_row.razor




<div class="B_Row" style="grid-template-columns : repeat(@Span,1fr)">
    @ChildContent
</div>

@code {
    [Parameter] 
    public RenderFragment ChildContent { get; set; }

    /// 
    /// 总分隔数,默认为12分隔
    /// 
    [Parameter]
    public string Span { get; set; } = "12";


}

B_row.razor.css

.B_Row {
    /*border: 1px solid black;*/
    display: grid;
    /*flex-direction: row;*/
    width: 100%;
    grid-template-columns: repeat(12,1fr);
    grid-auto-flow: column;
}

使用案例


<B_row>
    <B_col >1B_col>
B_row>
<B_row>
    <B_col  Span = "6">1B_col>
B_row>
<B_row>
    <B_col  Span = "6" Offset = "3">1B_col>
B_row>
<B_row>
    <B_col Span = "3">1B_col>
    <B_col Span = "3">2B_col>
    <B_col Span = "3">3B_col>
    <B_col Span = "3">4B_col>
B_row>

<B_row>
    <B_col Span = "4">1B_col>
    <B_col Span = "4">2B_col>
    <B_col Span = "4">3B_col>
    <B_col Span = "4">4B_col>
B_row>
<B_row Span="16">
    <B_col Span = "4" isBorder="true">1B_col>
    <B_col Span = "4">2B_col>
    <B_col Span = "4">3B_col>
    <B_col Span = "4">4B_col>
B_row>

在这里插入图片描述

你可能感兴趣的:(Blazor组件开发,Blazor)