You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React的reactstrap ModalHeader组件中右对齐Button组件?

How to Right-Align Buttons in Reactstrap ModalHeader (Flex Layout)

Hey there! Let's get those buttons aligned to the right in your ModalHeader. Since you're already using display: flex on the ModalHeader, we can use flexbox properties to fix this easily—float won't work here because flex containers ignore float styles entirely.

Here are a few clean, straightforward solutions:

Wrap your buttons in a container div and add the ml-auto class. This utility class sets margin-left: auto, which pushes the container to the far right in a flex layout. We'll also add align-items: center to the ModalHeader to keep the text and buttons vertically centered for a polished look:

<ModalHeader style={{ display: 'flex', alignItems: 'center' }}>
  Start Chatting
  <div className="ml-auto">
    <Button className="nav-btn" size="sm" style={{ marginLeft: '20px' }}>
      <i className="fa fa-plus-circle fa-lg" style={{ marginRight: '5px' }}></i>Create Room
    </Button>
    <Button className="end-chat" color="danger" size="sm" style={{ marginLeft: '10px' }}>
      <i className="fa fa-sign-out fa-lg"></i>End Chat
    </Button>
  </div>
</ModalHeader>

Solution 2: Inline Style with marginLeft: 'auto'

If you prefer not to rely on Reactstrap's utility classes, you can apply the margin directly via inline style:

<ModalHeader style={{ display: 'flex', alignItems: 'center' }}>
  Start Chatting
  <div style={{ marginLeft: 'auto' }}>
    <Button className="nav-btn" size="sm" style={{ marginLeft: '20px' }}>
      <i className="fa fa-plus-circle fa-lg" style={{ marginRight: '5px' }}></i>Create Room
    </Button>
    <Button className="end-chat" color="danger" size="sm" style={{ marginLeft: '10px' }}>
      <i className="fa fa-sign-out fa-lg"></i>End Chat
    </Button>
  </div>
</ModalHeader>

Solution 3: Use justify-content: space-between

Another option is to set justify-content: space-between on the ModalHeader. This will push the left-side text and right-side button container to opposite ends of the header:

<ModalHeader style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
  Start Chatting
  <div>
    <Button className="nav-btn" size="sm" style={{ marginLeft: '20px' }}>
      <i className="fa fa-plus-circle fa-lg" style={{ marginRight: '5px' }}></i>Create Room
    </Button>
    <Button className="end-chat" color="danger" size="sm" style={{ marginLeft: '10px' }}>
      <i className="fa fa-sign-out fa-lg"></i>End Chat
    </Button>
  </div>
</ModalHeader>

All these methods leverage flexbox's native alignment capabilities—no messy workarounds needed! Pick the one that fits your styling workflow best.

内容的提问来源于stack exchange,提问作者Abdul Ahad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 21:27:45