如果在新行中,如何使元素的宽度为 100%?

How to make a element to have width 100% if is in a new row?

  1. 我有一个 flex 行,包含 flex-wrap 内容
  2. 一个图标
  3. 文字可能很大
  4. 以及行尾的 Label 和 Button

目标是当 Label 和 Button 移动到新行时将它们放在行尾一次,因为文本太长。

非常小但复杂的问题...

   <div
      role="alert"
      className='relative ease-animation max-w-xxs sm:max-w-xs  md:max-w-sm lg:max-w-lg w-max shadow-bottom-lg rounded-md1 my-2 px-5 pb-4 flex items-center flex-wrap'
    >
      <div className="flex w-max mt-4 items-center">        
          <IconComponent  />
        <span
          className='tracking-extratight'
        >
          {text}
        </span>
      </div>
    
      {/* =======>>> Need this div ensure that the THIS DIV is on the right <<<============== */}
      <div className="h-3 w-max mt-3 flex-1 " />
        <div
          className="flex items-center w-auto justify-end self-end ml-3 "
          onClick={onCtaClick}
        >
          <span>
            {ctaText}
          </span>
          <CloseIcon />
        </div>
    </div>

截图:

添加text-endBootstrap Text Alignment

*注意: CSS 在此示例中仅用于演示目的 *

[role="alert"] {
color:white;
font-weight:bold;
max-width:500px;
float:right;
margin-right:10px;
box-shadow:2px 2px 5px rgba(0,0,0,.5)
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

   <div
      role="alert"
      class='bg-danger rounded relative w-max shadow-bottom-lg rounded-md1 my-2 px-5 pb-4 flex items-center flex-wrap'
    >
      <div class="flex w-max mt-4 items-center">        
          <IconComponent  />
        <span
          className='tracking-extratight'
        >
         There was an issue blablablablablababla !
        </span>
      </div>
    
      
      <div class="h-3 w-max mt-3 flex-1" />
        <div
          class="flex items-center text-end justify-end self-end ml-3 "
          onClick={onCtaClick}
        >
          <span>
            Retry X
          </span>
          <CloseIcon />
        </div>
    </div>

只需在 'Retry' 标签中添加 css 属性 margin left: auto 即可在框的最右侧看到标签和按钮