[英]How do you left align a div?
I Have tried to left align a div by using: 我试图通过使用以下方法使div左对齐:
<div class="col-md-3 float-left">
and 和
<div class="col-md-3" style="text-align: left;">
nothing I try is working? 我尝试的没有工作吗?
I tried the float now and the !important and still not working, so here is more of my code: 我现在尝试了float,!important仍然无法正常工作,所以这里有更多代码:
<div class="form-horizontal">
<h4>Branch</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group col-md-12">
<div class="col-md-2">
@Html.LabelFor(model => model.BranchName, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-3">
@Html.EditorFor(model => model.BranchName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BranchName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-12">
<div class="col-md-2">
@Html.LabelFor(model => model.Active, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-3" style="float: left !important;">
@Html.EditorFor(model => model.Active)
@Html.ValidationMessageFor(model => model.Active, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class=" col-md-offset-1 col-md-2">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
And here is a pic to see what I mean. 这是一张图片,了解我的意思。 It looks terrible with the checkbox and the textbox so far from their labels.
复选框和文本框距离它们的标签还很远,看起来很糟糕。
Can't tell you much without more code or a more specific description of the problem. 没有更多的代码或对该问题的更具体的描述,您将无法告诉您太多信息。 Regardless of that, my assumption is that you need the contents of a div left aligned?
无论如何,我的假设是您是否需要使div的内容保持对齐? By the class names you are using, I assume you are using Bootstrap.
根据您使用的类名,我假设您正在使用Bootstrap。 In that case, try adding this class to your div:
在这种情况下,请尝试将此类添加到div中:
text-left
If that doesn't work, try this: 如果这不起作用,请尝试以下操作:
style="text-align: left !important;"
If the second one works, you have CSS that is written somewhere else that is predominate, try to find this CSS and remove/change it. 如果第二个有效,则说明您在其他地方编写了CSS,请尝试查找此CSS并将其删除/更改。 If you are confused about this, read up on CSS Specificity .
如果对此感到困惑,请阅读CSS特异性 。 Do not leave the
!important
attached for no reason; 不要无缘无故地附加
!important
。 in general this is considered bad practice. 通常,这被认为是不良做法。
reference: http://getbootstrap.com/css/#type-alignment 参考: http : //getbootstrap.com/css/#type-alignment
You want to allign a div, and not a text. 您想分配一个div,而不是文本。 So you can use:
因此,您可以使用:
<div class="col-md-3" style="float:left">
For left align of a div 对于div的左对齐
<div style="float: left;"></div>
for left align of a text 用于文本的左对齐
<p style="text-align:left;"></p>
Try 尝试
<div class="col-md-1">
instead of 代替
<div class="col-md-2">
on your Label Div's The gap should come from the size of the col-md-2. 在标签Div上的间距应来自col-md-2的大小。 If you choose col-md-1 the gap should be smaller.
如果选择col-md-1,则间隙应较小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.