【问题标题】:Vertically align text in a bootstrap anchor (button)垂直对齐引导锚(按钮)中的文本
【发布时间】:2020-08-20 18:49:18
【问题描述】:

当 Bootstrap (3) <a><button> 中正常工作时,我正在努力垂直对齐文本

HTML:

<button class="btn">some text<span class="glyphicon glyphicon-play pull-right"></span></button>
</br>
</br>
</br>
<a href="#" class="btn">some text<span class="glyphicon glyphicon-play pull-right"></span></a>

CSS:

.btn {
  width: 315px;
  height: 40px;
  background-color: #ff38a4;
  color: #fff;
  display: inline-block;
  margin-bottom: 0;
  font-weight: normal;
  text-align: left;
  vertical-align: middle;
  -ms-touch-action: manipulation;
  touch-action: manipulation;
  cursor: pointer;
  background-image: none;
  border: 1px solid transparent;
  white-space: nowrap;
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1.42857143;
  border-radius: 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.5);
  -moz-box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.5);
  box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.5);
}

还有输出:

还有一个问题的代码:http://codepen.io/anon/pen/vyOaao

如何使用&lt;a&gt; 标签将文本和图标居中对齐?

【问题讨论】:

    标签: css twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    防止指定值行高:

    【讨论】:

    【解决方案2】:

    使用这个:

    a.btn {
      background-color: #ff38a4;
      border-radius: 0;
      box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.5);
      color: #fff;
      cursor: pointer;
      display: flex;
      font-size: 14px;
      font-weight: normal;
      justify-content: space-between;
      margin-top: 1rem;
      padding: 14px 14px 14px;
      width: 315px;
    }
    

    见小提琴:https://jsfiddle.net/ck0s48ab/

    在这里,和上面一样,你可以使用display: flex;

    【讨论】:

      【解决方案3】:

      不确定这是否适用于您的用例,但我刚刚遇到了这个问题,我选择了:

      <a href="#" role="button"><button class="btn" type="button">some text<span class="glyphicon glyphicon-play pull-right"></span></button></a>
      

      只需用锚标记包裹原始按钮。

      【讨论】:

        【解决方案4】:

        你为什么使用&lt;/br&gt;&lt;/br&gt;&lt;/br&gt;vertical-align with Bootstrap 3 可能对你有帮助

        【讨论】:

        猜你喜欢
        • 2013-09-27
        • 1970-01-01
        • 2021-02-14
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 2013-03-07
        • 1970-01-01
        • 2017-04-16
        相关资源
        最近更新 更多