flex上右对齐文本

flex上右对齐文本

本文介绍了在display flex上右对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

<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)看起来像这样:

The listContent (parent div) looks like this :

titleAndCounterBox看起来像这样:

And the titleAndCounterBox looks like this :

我想要的是titleAndCounterBox内部的文本右对齐.诸如:

What I want is that the text inside titleAndCounterBox is right aligned. Something like :

但是我无法对此进行简化.

But I'm not able to acommplish that.

任何建议我该怎么做?

推荐答案

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

You could change your CSS slightly :-) thanks to our discussion

.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;
   }
}

这篇关于在display flex上右对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:56