Semantic markup in react-bootstrap - Stack Overflow

admin2025-04-17  2

I am new to React and I would like to start using it right away with the react-bootstrap library. Now I am not sure how to integrate semantic element such as header, section and so on and use the container, row and col component in the same time.

With pure Bootstrap, i could basically do something like :

<header class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
    </div>
  </div>
</header>

and there I have my semantic element working as my bootstrap container.

Now using the react-bootstrap library, I guess I would do something like :

<Container className="main-header">
  <Row>
    <Col sm={6}>
      Some content here
    </Col>
  </Row>
</Container>

I did not look deeply into the abstraction but my guess is that those components will all become div elements.

So should I nest the whole thing into an extra semantic html element? or is there another conventional way to do it?

I am new to React and I would like to start using it right away with the react-bootstrap library. Now I am not sure how to integrate semantic element such as header, section and so on and use the container, row and col component in the same time.

With pure Bootstrap, i could basically do something like :

<header class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
    </div>
  </div>
</header>

and there I have my semantic element working as my bootstrap container.

Now using the react-bootstrap library, I guess I would do something like :

<Container className="main-header">
  <Row>
    <Col sm={6}>
      Some content here
    </Col>
  </Row>
</Container>

I did not look deeply into the abstraction but my guess is that those components will all become div elements.

So should I nest the whole thing into an extra semantic html element? or is there another conventional way to do it?

Share Improve this question edited Feb 5 at 12:52 shotor 1,06210 silver badges28 bronze badges asked Feb 1 at 11:06 Yannick FerencziYannick Ferenczi 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You're looking for the as property:

https://react-bootstrap.netlify.app/docs/getting-started/introduction#as-prop-api

So your code becomes:

<Container as="header" className="main-header">
  <Row>
    <Col sm={6}>
      Some content here
    </Col>
  </Row>
</Container>
转载请注明原文地址:http://anycun.com/QandA/1744830759a88218.html