【问题标题】:Styling of Even/Odd Divs in ReactjsReactjs 中偶数/奇数 div 的样式
【发布时间】:2021-04-24 23:33:04
【问题描述】:

我正在尝试设置奇数类和偶数类的样式,但代码未按预期工作。它将所有类都设计为一个。通过我的代码和输出,这将更容易理解。 输出: 代码:

.b1-segment:nth-child(even) .description-wrapper{
  color: white;
  float: left;
}
.b1-segment:nth-child(odd) .description-wrapper{
  color: black;
  float: right;
}
  {getallservices.map((service) => {

              return(
                <>
                <Fade bottom>
                   <section className="services banner-page about  b1-segment bg-fx" style={{ backgroundImage:   `url(${service.imgDesk.fluid.src})` }}>
                      <Container>
                        <Row>
                          <Col md={12}>
                              <div className="description-wrapper">
                                  <h3>{service.servicesHeading}</h3>
                                  <p>{service.description.description}</p>
                                  
                              </div>
                          </Col>
                        
                        </Row>
                      </Container>
                   </section>
                </Fade>
             
                </>

              )

            })}

【问题讨论】:

    标签: javascript css reactjs react-bootstrap


    【解决方案1】:

    &lt;Fade bottom&gt;.b1-segment 是唯一的孩子。所以.b1-segment:nth-child(odd)会一直被选中。

    如果您想选择.b1-segment 作为直接子级,您必须将section 标记作为主要包装器。然后.b1-segment 将被视为子元素,在其中呈现并且您的 css 将起作用。

      {getallservices.map((service) => {
    
              return(
                <>
                  <section className="services banner-page about  b1-segment bg-fx" style={{ backgroundImage:   `url(${service.imgDesk.fluid.src})` }}>
                    <Fade bottom>
                      <Container>
                        <Row>
                          <Col md={12}>
                              <div className="description-wrapper">
                                  <h3>{service.servicesHeading}</h3>
                                  <p>{service.description.description}</p>  
                              </div>
                          </Col>
                        </Row>
                      </Container>
                    </Fade>
                  </section>
                </>
              )
            })}
    

    【讨论】:

    • 我试过了,输出和以前一样,它仍然没有考虑两个孩子...我知道某处有一个小错误,但我似乎找不到它。
    猜你喜欢
    • 2012-10-01
    • 2013-06-10
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    相关资源
    最近更新 更多