简体   繁体   English

如何将引导按钮与文本连续垂直对齐?

[英]How to vertically align bootstrap buttons with text in a row?

I'm having a problem with bootstrap rows. 我遇到了bootstrap行的问题。 My buttons are not vertically aligning with my row text. 我的按钮没有与行文本垂直对齐。 Here's an example of the problem: 这是一个问题的例子:

在此输入图像描述

<div class="col-md-2 text-right">
    <button class="btn btn-lg btn-primary" type="button">A</button>
</div>
<div class="col-md-1 text-center">
    <h3>or</h3>
</div>
<div class="col-md-2 text-left">
    <button class="btn btn-lg btn-primary" type="button">B</button>
</div>

The text even hangs below the buttons if I make it any larger, like so: 如果我把它做得更大,文本甚至会挂在按钮下面,如下所示

在此输入图像描述

<div class="col-md-1 text-center">
    <h1>OR</h1> <!-- H1 now! -->
</div>

Is there any way to get the bottom of "or" to line-up with the bottom of the button text? 有没有办法让“或”的底部与按钮文本的底部对齐? Or even just have the text be centered with the buttons? 或者甚至只是让文本以按钮为中心? Thanks! 谢谢!

Update: here's a JSFiddle, as requested: http://jsfiddle.net/Dk37C/1/ (you'll have to stretch the right side display to see the behavior) 更新:这是一个JSFiddle,按要求: http//jsfiddle.net/Dk37C/1/ (你必须拉伸右侧显示才能看到行为)

I found an easy way using bootstrap classes for text and a button in an MVC View, but I am pretty sure the idea will apply where ever you can use Bootstrap. 我找到了一种使用文本引导类和MVC视图中的按钮的简单方法,但我很确定这个想法适用于可以使用Bootstrap的地方。

Just put the same header class, for example h3, in the class attributes of both the text and the button. 只需将相同的头类(例如h3)放在文本和按钮的类属性中。

for example: 例如:

<div class="col-md-6 h3">
    Mileage Reimbursed Travel
</div>

<div class="col-md-2 h3">
    @Html.ActionLink("Create/Add ","Create", "EmployeeMileage")
</div>

The <h3> has a margin set on it, so if it gets bigger, the margin top will stay the same but the size of the font will increase 'downwards'. <h3>上设有边距,因此如果它变大,边距顶部将保持不变,但字体的大小将“向下”增加。

You could set the styles of the <h3> to match those of the button, ie the padding, the line-height, the font-size, etc. 您可以设置<h3>的样式以匹配按钮的样式,即填充,行高,字体大小等。

.text-center h3 {
  padding: 11px 16px; /* Extra pixel top and bottom for border on buttons */
  font-size: 18px;
  line-height: 1.33;
  border-radius: 6px;
  margin: 0;
}

http://jsbin.com/UNAYOqU/1/edit http://jsbin.com/UNAYOqU/1/edit

I think you can try to use the vertical-align css property. 我想你可以尝试使用vertical-align css属性。 Here is a good write up of how to use vertical align. 这里有一个关于如何使用垂直对齐的好文章。

If you are in a hurry, (i'm not saying this is the best solution but hey, it works) put the text you want to align with your button in another button, then use CSS to remove things like the background and the border and disable the button. 如果你赶时间,(我不是说这是最好的解决方案,但嘿,它的工作原理)将你想要与你的按钮对齐的文本放在另一个按钮中,然后使用CSS去除背景和边框之类的东西并禁用该按钮。 I use this solution every once in a while and it works great. 我每隔一段时间都会使用这个解决方案,效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM