C# 在MVC中,将其标签上的复选框居中

C# 在MVC中,将其标签上的复选框居中,c#,asp.net-mvc,checkbox,view,C#,Asp.net Mvc,Checkbox,View,在我的项目中,我正在处理一些只有几个字段的索引视图。当表中只有几个字段时,它们下面的标签和复选框永远不会对齐。例如,在下面的代码中,活动字段是一个复选框,它不在其标签下。如何使复选框位于其标签的中心 <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.BranchName) </th>

在我的项目中,我正在处理一些只有几个字段的索引视图。当表中只有几个字段时,它们下面的标签和复选框永远不会对齐。例如,在下面的代码中,活动字段是一个复选框,它不在其标签下。如何使复选框位于其标签的中心

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.BranchName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Active)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model.OrderByDescending(m => m.Active).ThenBy(m => m.BranchName))
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.BranchName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Active)
        </td>
        <td>
            @Html.ActionLink("Edit", "EditBranch", new { id=item.BranchId })
        </td>
    </tr>
}

</table>

@DisplayNameFor(model=>model.BranchName)
@DisplayNameFor(model=>model.Active)
@foreach(Model.OrderByDescending(m=>m.Active)中的var项,然后by(m=>m.BranchName))
{
@DisplayFor(modelItem=>item.BranchName)
@DisplayFor(modeleItem=>item.Active)
@ActionLink(“编辑”、“编辑分支”,新的{id=item.BranchId})
}
下面是一张照片,看看它看起来有多难看:


通过colspan或direct on td或th向列中添加css

<td style="text-align: center">
否则,将@Html.DisplayFor封装在具有该样式的div中


最后,不要让css内联并移动到style.css文件。

据我所知,这似乎不是默认行为。默认情况下,复选框应与header@JamieD77看我贴在下面的图片。也许有一个css的变化?
style="float:left"