在与其他元素相同的行上显示React组件

时间:2017-04-26 20:02:58

标签: javascript reactjs sass

我正在尝试获取一个我构建的React组件,以与文本的其余部分显示在同一行,但它仍然显示在与其他元素不同的行上。

这是我的React代码:

<div className={styles['top']}>
    <span>WHAT PEOPLE ARE SAYING</span>
    <div className={`pull-right ${styles['right']}`}>
      <span className={`${styles['rating-words']}`}>{ratingWords}</span>
      <Rating className={`${styles['overall-stars']}`}
              percentage={this.state.overallPercentage}
              color={"#00c18a"}
              under={"white"}
      />

    </div>
  </div>

和.scss:

.top {
  margin: 30px 0;
  font-weight: bold;
  .right {
    display: inline-block;
    flex-direction: row;
  }
  .rating-words {
    text-transform: uppercase;
  }
}

最后,看看它的样子:

enter image description here

“非常好”和评级星都应该在同一条线上。知道如何解决这个问题吗?

4 个答案:

答案 0 :(得分:1)

如果.top中有两个子元素,那么这应该有效。

fiddle

.top {
  margin: 30px 0;
  font-weight: bold;
  display: flex;
  flex-direction: row;
  justify-content: space-between;

  .rating-words {
    text-transform: uppercase;
  }
  .right {
  }
}

答案 1 :(得分:1)

如果你发布一个有效的jsfiddle或codepen,它会更容易提供帮助。

尝试提供overall-stars课程display: inline-block。我认为它已经是一个块元素,这使它出现在一个新的行上。

答案 2 :(得分:1)

我最终根据@Chad的说法得到了以下内容,尽管@torkjels所说的最终在另一个地方工作得更好。

.top {
  margin-top: 40px;
  margin-bottom: 30px;
  font-weight: bold;
  .right {
    display: inline-flex;
    flex-direction: row;
  }
  .rating-words {
    text-transform: uppercase;
    margin-right: 10px;
  }
  .overall-stars {
    margin-top: -2px;
  }
}

答案 3 :(得分:0)

const top = {
    // Other styles
    display: 'flex',
    flexDirection: 'row',
}

可能有帮助。