html - 显示 Flex 上的文本右对齐

标签 html css sass flexbox

我的代码如下:

<div className="listContent">
     <div>
        <div className="titleAndCounterBox">
           <div className="headerListTitle">{list.name}</div><br />
           <div className="headerListExpires">
                 <div>{formatTime(this.state.remainingTime).days}<span>{language.days}</span></div>
                 <div>{formatTime(this.state.remainingTime).hours}:{formatTime(this.state.remainingTime).minutes}:{formatTime(this.state.remainingTime).seconds}</div>
            </div>
        </div>
        <div><img src={images.header_listInfo_png} /></div>
        <div className="headerTotalCarsInTheList"><span>{totalCarsInTheList}</span></div>

    </div>
</div>

我的scss如下:

.listContent {
    display: flex;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    font-family: $remarketingFontFamily;

    div {
      display: flex;
      align-items: center;

      .titleAndCounterBox {
        flex-wrap: wrap;

        .headerListTitle {
          font-size: $portalFontSize - 1;
          color: $portalBlueColor;
          flex-basis: 100%;
        }

        .headerListExpires {
          font-size: $portalFontSize - 3;
          color: $portalYellow;

          div:first-child {
            margin-right: 15px;
          }
        }
      }

      .headerTotalCarsInTheList {

        text-align: center;
        line-height: 40px;
        color: $portalDarkGrey;
        font-size: $infoTextSize + 6;
        border: 1px solid $portalDarkGrey;
        border-radius: 50%;
        margin: 0 15px;

        span{
          width: 40px;
          height: 40px;
        }
      }
    }


  }

listContent(父 div)如下所示:

enter image description here

titleAndCounterBox 看起来像这样:

enter image description here

我想要的是 titleAndCounterBox 内的文本右对齐。类似于:

enter image description here

但我无法实现这一点。

有什么建议我该怎么做吗?

最佳答案

由于我们的讨论,您可以稍微更改一下 CSS :-)

.headerListTitle { 
   font-size: $portalFontSize - 1; 
   color: $portalBlueColor;

   margin-left: auto; 
   flex-basis: 58%; 
  //you could replace these 2 lines with below 2 lines if you wish

  //justify-content: flex-end;
  //flex-basis: 89% (same as below row)

} 

.headerListExpires { 
   font-size: $portalFontSize - 3; 
   color: $portalYellow; 
   flex-basis: 89%; 

   div:first-child { 
      margin-left: auto; 
      margin-right: 15px; 
   } 
}

关于html - 显示 Flex 上的文本右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40283929/

相关文章:

JavaScript 无法显示数组中的图像

css - 如何根据内容水平增长一个div?

javascript - 修改:after pseudo CSS element from JQuery的宽度

html - 如何将具有动态宽度的输入文本放入表格中?

css - Sass DataURIs 未闭合的引号

css - 有什么办法可以用 CLI 强制监视 node-sass 吗?

html - 文本区域内按钮的绝对定位

javascript - 将 CSS-Accordion 应用于不同的按钮

html - 使用 CSS 创建 block 悬停效果的最佳实践

html - 在 Sass 中,我如何根据它的父对象定位特定的子对象,然后在媒体查询中使用它?