代码之家  ›  专栏  ›  技术社区  ›  Imrul.H

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

css
  •  0
  • Imrul.H  · 技术社区  · 11 年前

    我正在用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 回复  |  直到 11 年前
        1
  •  2
  •   Pete Irfan TahirKheli    11 年前

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

    Example