什么是将SVG与按钮垂直对齐的最佳方法?

时间:2016-09-26 01:59:01

标签: css svg

如何垂直对齐这些SVG图像以垂直匹配我正在制作的按钮?

<button style=
"width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
Step 1<br>
.</button> <svg height="50" viewbox="0 0 512 512" width="50" xmlns=
"http://www.w3.org/2000/svg">
<path d=
"M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
</path></svg> <button style=
"width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
Step Two<br>
.</button> <svg height="50" viewbox="0 0 512 512" width="50" xmlns=
"http://www.w3.org/2000/svg">
<path d=
"M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
</path></svg> <button style=
"width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
Step 3<br>
.</button>

jsfiddle

1 个答案:

答案 0 :(得分:3)

2018年5月7日更新

  • 添加了display: flex选项


您可以像这样设置按钮和svg的样式:

button,
svg {
  display: inline-block;
  vertical-align: middle;
}

&#13;
&#13;
button,
svg {
  display: inline-block;
  vertical-align: middle;
}
&#13;
<h2>Using display inline block and vertical align middle</h2>

<button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
    Step 1<br>.
</button>

<svg height="50" viewbox="0 0 512 512" width="50" xmlns="http://www.w3.org/2000/svg">
    <path d=
    "M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
    </path>
</svg>

<button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
    Step Two<br>.
</button>

<svg height="50" viewbox="0 0 512 512" width="50" xmlns="http://www.w3.org/2000/svg">
    <path d=
    "M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
    </path>
</svg>

<button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
    Step 3<br>.
</button>
&#13;
&#13;
&#13;

希望这有帮助。


展示广告

您也可以使用display: flex browser that is supported来实现此目的。但需要为按钮和svg添加额外的包装。

&#13;
&#13;
@supports (display: flex) {
  .steps {
    display: flex;
    flex-direction: row;
    align-items: center;
  }
}
&#13;
<h2>Using display flex</h2>
<div class="steps">
  <button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
      Step 1<br>.
  </button>

  <svg height="50" viewbox="0 0 512 512" width="50" xmlns="http://www.w3.org/2000/svg">
      <path d=
      "M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
      </path>
  </svg>

  <button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
      Step Two<br>.
  </button>

  <svg height="50" viewbox="0 0 512 512" width="50" xmlns="http://www.w3.org/2000/svg">
      <path d=
      "M 64.00,416.00l 96.00,96.00l 256.00-256.00L 160.00,0.00L 64.00,96.00l 160.00,160.00L 64.00,416.00z">
      </path>
  </svg>

  <button style="width:100px;height:100px;border-radius:50%;background-color:white;border-color:#0F75BC;">
      Step 3<br>.
  </button>
</div>
&#13;
&#13;
&#13;

相关问题