簡體   English   中英

如何對齊文本並將按鈕放在灰色條的最右側?

[英]How can I align my text and put the button on the extrem right of my gray bar?

我怎樣才能在我的灰色欄中顯示我的 Invitee2 有點高? 對於我的按鈕,我怎樣才能將它放在灰色條的最右側?

<div className="bg-gray-200 p-5 h-5 pl-2 mb-2 text-md text-primary-500  font-bold  text-gray-500">
Invitee {i + 1}
<span className="float-right -mt-5">
    {!!i && (
        <Button primary className="rounded-md float-right mt-4" onClick={() => removeInvitee(pId)}>
            - Invitee
        </Button>
    )}
</span>

Button.jsx

export default function Button({ onClick,primary,children,disabled }) {
    return <button
        onClick={onClick}
        className={`${primary
            ? ' cursor-pointer rounded-md bg-primary-700 py-2 px-3  text-white  hover:bg-blue-700 hover:text-white'
            : 'bg-transparent  text-gray border border-primary-500 hover:border-primary-100 hover:text-primary-100 transition duration-200 '} 
            text-primary-fg py-2 px-3 rounded-md transition-colors `}
        disabled={disabled}
    >{children}</button>
}

這是一張圖片來了解這個想法: 圖片

div類中添加flex flex-row justify-between items-center

並刪除float-right旁邊的span類中的-mt-5

檢查下面的代碼

<div className="flex flex-row justify-between items-center bg-gray-200 p-5 h-5 pl-2 mb-2 text-md text-primary-500  font-bold  text-gray-500">
Invitee {i + 1}
  <span className="float-right">
      {!!i && (
          <Button primary className="rounded-md float-right mt-4" onClick={() => removeInvitee(pId)}>
              - Invitee
          </Button>
      )}
  </span>
</div>

您可以使用 flexbox 屬性來制作您想要的設計。 我在下面創建了非常相似的示例,請在此處添加您的函數並將class替換為className

 <script src="https://cdn.tailwindcss.com"></script> <div class="container mx-auto py-4"> <div class="bg-gray-200 text-md flex items-center justify-between rounded-r-md"> <div class=" font-bold text-gray-500 ml-4" >Invitee 2</div> <div class=""> <Button primary class="rounded-md bg-black text-white py-2 px-4" onclick="removeInvitee(pId)"> - Invitee </Button> </div> </div> </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM