在按钮中间显示文本和图标

时间:2015-01-28 14:01:38

标签: css

我正在用html5和css3编写一个按钮。以下是不同尺寸的外观:enter image description here

您可以看到图标不在中间。我知道为什么会这样。但是如何在中间设置图标?这是我的代码:

<a href="#" title="" class="blue-pill centered" role="button"><i class="icon">a</i><span>start</span></a>

CSS:

.blue-pill {
  display: block;
  text-decoration: none;
  width: 135px;
  height: 50px;
  margin-bottom: 15px;
  position: relative;
  background-color: #002032;
  border: none;
  color: #FFF;
  text-transform: uppercase;
  font-family: 'Open Sans Condensed', sans-serif;
  font-weight: 700;
  font-size: 14px;
  padding: 0;
  border-radius: 50px;
  cursor: pointer;
  z-index: 2;
  text-align: center;
  line-height: 50px;
  -webkit-box-shadow: 0px 5px 0px #1488ae;
  -moz-box-shadow: 0px 5px 0px #1488ae;
  box-shadow: 0px 5px 0px #1488ae;
}
.blue-pill .icon {
  display: inline-block;
  margin: 0 5px;
  color: #e57125;
  font-size: 20px;
}
.blue-pill span {
  display: inline-block;
}
.blue-pill.centered {
  margin-left: auto;
  margin-right: auto;
}
.blue-pill.inline {
  display: inline-block;
  margin-left: 5px;
  margin-right: 5px;
}

我正在使用图标字体作为图标。这就是我想要的:

enter image description here

1 个答案:

答案 0 :(得分:2)

vertical-align:middle添加到.blue-pill .icon.blue-pill span

Example