【问题标题】:How to set Antd icon as a ::before pseudo selector of a button?如何将 Antd 图标设置为按钮的 ::before 伪选择器?
【发布时间】:2020-07-13 23:34:49
【问题描述】:

目前,我将图标作为道具传递给按钮组件

<div className="offer-actions">
          <Button type="link" icon={<EyeOutlined />}>
            View
          </Button>
          {offer.pause ? (
            <Button type="link" icon={<PlayCircleOutlined />}>
              Resume
            </Button>
          ) : (
            <Button type="link" icon={<PauseCircleOutlined />}>
              Pause
            </Button>
          )}
          <Button type="link" icon={<EditOutlined />}>
            Edit
          </Button>
</div>

它在页面上是这样渲染的

我想让图标出现在按钮文本的左侧

我尝试添加 CSS 伪选择器 :before 但不确定要添加到内容中的内容

:before
{
    position:absolute;
    content:"";
}

【问题讨论】:

    标签: css reactjs antd


    【解决方案1】:

    只需覆盖按钮上的文本对齐方式

    <Button type="link" className="my-custom-button" icon={<EyeOutlined />}>
      View
    </Button>
    
    .my-custom-button {
      text-align: left
    }
    

    【讨论】:

    • 很好,很有效。还是想知道伪选择器方法。
    • 我想要实际问题的答案,而不是解决方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 2017-06-07
    • 2012-02-23
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多