【发布时间】:2019-09-18 18:36:40
【问题描述】:
标签(“酸性稳定氨基酸”)和复选框位于我的 ASP.NET Core MVC 应用程序中的不同行。 (样品 ID 在这里无关紧要。)我希望他们在同一行。当前未对齐的输出:
模型中的字段:
[Display(Name = "Acid-stable amino acids")]
public bool AcidStables { get; set; }
Razor 视图(删除大多数其他不相关的元素):
<div class="row">
<div class="col-md-6">
<form asp-action="Create">
<div class="form-group">
<label asp-for="ClientSampleID" class="control-label"></label>
<input asp-for="ClientSampleID" class="form-control" />
<span asp-validation-for="ClientSampleID" class="text-danger"></span>
</div>
<div class="checkbox">
<label asp-for="AcidStables" class="control-label"></label>
<input asp-for="AcidStables" class="form-control"/>
<span asp-validation-for="AcidStables" class="text-danger"></span>
</div>
</div>
</div>
我尝试了一些类似问题中推荐的方法。在标签前使用 inline-block 显示:
<div class="checkbox">
<style type="text/css">
label {
display: inline-block;
}
</style>
或者修改site.css文件中的label或者checkbox类型:
.label {
display: inline;
font-size: 1.2em;
font-weight: 600;
padding: 5px;
}
input[type=checkbox] {
float: left;
margin-right: 0.4em;
}
或
input[type=checkbox] + label {
display: inline-block;
margin-left: 0.5em;
margin-right: 2em;
line-height: 1em;
}
我已尝试更改为“form-horizontal”。
没有改变复选框和标签的对齐方式。任何输入将不胜感激。浮动复选框可能是一个解决方案,但我不知道该怎么做。相关 SO 问题:here、here、here。
【问题讨论】:
-
你使用什么版本的引导程序?
-
在_Layout.cshtml文件中,stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/…
-
你能发布关于
input[type=checkbox]的代码 -
对不起,我不确定你的意思?
-
在您发布的代码中,我看不到
type="checkbox"的任何输入
标签: c# html css asp.net-mvc razor