我想要Designinig SASS的Box布局,但无法获得它

时间:2019-03-06 06:29:14

标签: css reactjs user-interface sass styling

就像我想要获得这种布局enter image description here

<div>
  {iconElement}
  <div className='id-count-title'>
    {title}     
    <div className='id-count-description'>
      {description}
    </div>
  </div>
</div>

我尝试编写CSS并为其设置样式,

.id-count-title {
  width: 37px;
  height: 32px;
  left: 443px;

    font-family: Open Sans;
    font-style: normal;
    font-weight: bold;
    font-size: 32px;
    text-align: center;

    color: #4CA6EA;
}

.id-count-description {
    width: 58px;
    height: 16px;
    left: 432px;
    font-family: Open Sans;
    font-style: normal;
    font-weight: normal;
    line-height: 16px;
    font-size: 11px;
    text-align: center; 
}

通过这个样式类,我得到enter image description here

如何实现所需的样式?

2 个答案:

答案 0 :(得分:1)

使用flexbox,这是flexbox的指南:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

根据需要选择使容器显示:flex justify-content:环绕分隔

.flex {
  display: flex;
  justify-content: space-around;
  background: #135;
  padding: 10px;
  color: #fff;
  text-align: center;
}

.flex span {
  font-size: 24px;
  display: block;
}

.flex .active {
  color: #4CA6EA;
}
<div class="flex">
  <div class="active"><span>18</span>Users</div>
  <div><span>1</span>Native</div>
  <div><span>17</span>Non-native</div>
</div>

答案 1 :(得分:1)

我认为Flexbox正是您所需要的。 您可以通过以下方式更改代码:

html:

<div className="id-block">
  <div className="icon">
    {iconElement}
  </div>
  <div className="text">
    <div className='id-count-title'>
      {title}
    </div>
    <div className='id-count-description'>
      {description}
    </div>
  </div>
</div>

css / sass:

.id-block {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.text {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.id-count-title {
    width: 37px;
    height: 32px;
    left: 443px;
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: bold;
    font-size: 32px;
    text-align: center;
    color: #4CA6EA;
}

.id-count-description {
    width: 58px;
    height: 16px;
    left: 432px;
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: normal;
    line-height: 16px;
    font-size: 11px;
    text-align: center;
}