【问题标题】:text and icon in a antd button are not aligned verticallyantd 按钮中的文本和图标未垂直对齐
【发布时间】:2022-02-06 07:12:15
【问题描述】:

我的问题是我的 antd 按钮中的文本和图标在我的 react 应用程序中没有垂直对齐。

代码如下:

             <Button type="primary" size="large" block icon={<PlusCircleOutlined />} onClick={()=>this.showModalSharePicture()}>
          Text
          </Button>

与文本相比,图标有点低,女巫在按钮中居中。 如何解决我所有按钮中的这个问题?

这里是渲染的 html:

<button type="button" class="ant-btn ant-btn-primary ant-btn-lg ant-btn-block"><span role="img" aria-label="plus-circle" class="anticon anticon-plus-circle"><svg viewBox="64 64 896 896" focusable="false" data-icon="plus-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg></span><span>Text</span></button>

【问题讨论】:

  • 它可能有助于提供呈现的 HTML 和相关的 CSS 来演示问题的working example
  • 您好,我刚刚添加了渲染的 html。但是您可以在这里看到一个工作示例:app.tipmymeme.com

标签: javascript css reactjs antd


【解决方案1】:

一种可能的方法是使用以下样式:

button,
span {
  display: inline-flex;
  align-items: center;
}

您还可以使用他们的类名ant-btnanticon 来根据您的喜好和需求来设置它们的样式。

【讨论】:

  • 谢谢,它适用于类名。
猜你喜欢
  • 2013-07-02
  • 2013-03-07
  • 2021-04-27
  • 2017-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多