2017-04-26 68 views
1

我试图获得一个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

两者“非常好“,评级明星应该在同一条线上。任何想法如何解决这个问题?

+1

输出的HTML是什么样的?我认为这与HTML + CSS更接近于React。 – Whymarrh

回答

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

如果您发布工作的jsfiddle或codepen它会更容易帮助。

尝试给你的overall-starsdisplay: inline-block。我认为它已经是一个块元素,这使得它出现在一个新的线上。

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; 
    } 
} 
相关问题