简体   繁体   English

使用 SVG 内部按钮修复 HTML 按钮错位

[英]Fix HTML button misplacement with SVG inside button

When buttons are placed together, the buttons positions are broken when one of the buttons has an SVG inside it.当按钮放在一起时,当其中一个按钮内部有 SVG 时,按钮位置会被破坏。

For example, with this code:例如,使用此代码:

<style>
button {
  height: 36px;
}
</style>
<button>Button with Text</button>
<button>
   <svg
          width="24"
          height="24"
          focusable="false"
          viewBox="0 0 24 24"
          xmlns="http://www.w3.org/2000/svg"
          data-icontype="Check"
     >
     <path
            fill-rule="evenodd"
            clip-rule="evenodd"
            d="M17.8062 7.37181C18.0841 7.67897 18.0603 8.15325 17.7532 8.43115L9.8782 15.5562C9.59605 15.8114 9.16747 15.815 8.88113 15.5644L5.88113 12.9394C5.5694 12.6667 5.53782 12.1928 5.81058 11.8811C6.08334 11.5694 6.55716 11.5378 6.86889 11.8106L9.36667 13.9961L16.7468 7.31885C17.054 7.04094 17.5283 7.06466 17.8062 7.37181Z"
     ></path>
   </svg>
</button>

The button with the icon is much higher than the icon without the icon带图标的按钮比不带图标的图标高很多

https://codesandbox.io/s/winter-bird-fn8hr?fontsize=14&hidenavigation=1&theme=dark https://codesandbox.io/s/winter-bird-fn8hr?fontsize=14&hidenavigation=1&theme=dark

How can I get the buttons to be vertically aligned?如何让按钮垂直对齐?

The answer is to embed the buttons in a答案是将按钮嵌入到

<div style="display:flex">
...
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM