对齐按钮

时间:2017-05-24 13:07:23

标签: html css twitter-bootstrap bootstrap-4 twitter-bootstrap-4

我需要在左侧制作带图标的按钮,我在这里找到了一个很好的例子。但无论我编辑多少,内部文本都不会垂直对齐。顺便说一句,我正在使用Bootstrap 4。有人帮忙吗?

这是原始fiddle

这是代码:

.btn {
  text-align: center;
  font-size: 0.7em;
  text-transform: uppercase;
  background: #42473d;
  padding: 1em 0.5em;
  color: #fff;
}

.btn-primary:before {
  font-family: 'FontAwesome';
  font-size: 2em;
  width: (18em / 14);
  float: left;
  margin: -0.5em -0.2em;
  padding: 0.3em 0.6em;
  background-color: #292c26;
  content: "\f230";
}
.btn-secondary:before {
  font-family: 'FontAwesome';
  font-size: 2em;
  width: (25em / 14);
  float: left;
  margin: -0.5em -0.2em;
  padding: 0.3em 0.6em;
  background-color: #292c26;
  content: "\f179";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>

2 个答案:

答案 0 :(得分:3)

如果您使用Chrome工具检查器,您可以看到正确添加了填充,但问题在于文本本身。添加初始/正常的行高,它可以解决问题。

.btn {
    text-align: center;
    font-size: 0.7em;
    text-transform: uppercase;
    background: #42473d;
    padding: 1em 0.5em;
    color: #fff;
    line-height: initial;
}

答案 1 :(得分:0)

我希望它能解决你的问题。

&#13;
&#13;
.btn {
  text-align: center;
  font-size: 0.7em;
  text-transform: uppercase;
  background: #42473d;
  padding: 1em 0.5em;
  color: #fff;
  position: relative;
  height: 40px;
  overflow: hidden;
}

.btn:before {
  font-family: 'FontAwesome';
  font-size: 1.5em;
  float: left;
  padding: 4px 10px;
  height: 40px;
  width: 40px;
  background-color: #292c26;
  content: "\f230";
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>
<button class="btn btn-block rounded-0">
    View Using Facebook
</button>
&#13;
&#13;
&#13;