【发布时间】:2025-12-22 03:40:15
【问题描述】:
我们有以下 <Row> 和 2 个 <Col> 元素:
<Row>
<Col xs={12} sm={{ span: 9, offset: 1 }} md={{ span: 6, offset: 0 }} lg={5} xl={4}>
<h3 className='graph-header-1'>First Header</h3>
<div>Graph that fills the col-width goes here</div>
</Col>
<Col xs={12} sm={{ span: 9, offset: 1 }} md={{ span: 6, offset: 0 }} lg={{ span: 5, offset: 1 }} xl={{ span: 4, offset: 2 }}>
<h3 className='graph-header-1'></h3>
<div>2nd Graph that fills the column's width goes here</div>
</Col>
</Row>
这种布局(有 2 个列的行,每个 xs、sm、md、lg、xl 都有这些特定的跨度/偏移量)将在我们应用程序的几个地方使用。是否可以将其保存在一个类中,这样我们就不必一遍又一遍地设置这些值,而只需使用:
<Row className='our-responsive-layout'>
<Col>
<h3 className='graph-header-1'>First Header</h3>
<div>Graph that fills the col-width goes here</div>
</Col>
<Col>
<h3 className='graph-header-1'></h3>
<div>2nd Graph that fills the column's width goes here</div>
</Col>
</Row>
...our-responsive-layout 是一个处理 2 列的跨度/偏移量的类?或者,为每列设置一个类(而不是为 2 列的行设置一个类)也会有所帮助。
编辑:如果有任何关于使用 react-bootstrap 及其容器/行/列组件在复杂的 react-app 中处理响应性的详尽指南,请分享。我担心在我们的应用中添加xs={12} sm={{ span: 9, offset: 1 }} md={{ span: 6, offset: 0 }} lg={{ span: 5, offset: 1 }} xl={{ span: 4, offset: 2 }} 之类的东西会使代码更加混乱。
谢谢!
【问题讨论】:
标签: css reactjs react-bootstrap bootstrap-grid