reactjs 在React Bootstrap中添加行元素之间的空格

v64noz0r  于 2023-10-17  发布在  React
关注(0)|答案(3)|浏览(170)

我是React和react-bootstrap的新手。我有一个行组件,并希望屏幕顶部之间的间距,也是个别行元素之间。我目前只是编辑它的CSS,但听说它可能是不好的混乱与CSS的框架?

  1. const Styles = styled.div`
  2. .background {
  3. background: url(${backgroundImage}) no-repeat fixed bottom;
  4. background-size: cover;
  5. height: 100vh;
  6. position: relative;
  7. }
  8. #row {
  9. position: relative;
  10. top: 200px;
  11. }
  12. `;
  13. class Signup extends React.Component {
  14. render() {
  15. return (
  16. <Styles>
  17. <div className="background">
  18. <Container>
  19. <Row id="row" className="justify-content-md-center">
  20. <ExtraInfo />
  21. <SignupForm />
  22. </Row>
  23. </Container>
  24. </div>
  25. </Styles>
  26. );
  27. }
  28. }
  29. export default Signup;

bvk5enib

bvk5enib1#

  1. import Stack from 'react-bootstrap/Stack';
  2. <Stack gap={3}>
  3. {/* your code */}
  4. </Stack>
ijxebb2r

ijxebb2r2#

在React-Bootstrap中使用Form.Group。它在列上添加15 px的填充以分隔列的内容。

xwbd5t1u

xwbd5t1u3#

我并不是说这是最好的解决方案,但我刚刚创建了一个CSS类,它将margin属性设置为5px,然后将其应用于需要它的Row元素。这对我来说很有效,但我欢迎更好的答案。
对于屏幕顶部和底部的空间,我所做的是创建一个“spacer”组件,我导入并使用它来创建元素之间的空间。
我知道你的意思是什么与CSS混乱虽然和这个方法可能有点“黑客”。
示例JSX:

  1. <>
  2. <p><strong>My Categories</strong></p>
  3. {
  4. catList.map((cat,i) => (
  5. <Row key={i} className="add-space">
  6. <Col><strong>Category {i+1}</strong></Col>
  7. <Col>{cat}</Col>
  8. <Col><Button onClick={() => removeCategory(cat)}>Remove</Button></Col>
  9. </Row>
  10. ))
  11. }
  12. </>

CSS示例:

  1. .add-space {
  2. margin: 4px;
  3. }

示例间隔物:

  1. const Spacer = props => {
  2. return (
  3. <div style={{height:props.height}}></div>
  4. );
  5. }
  6. export default Spacer;

用途:

  1. <Spacer height="1rem" />
展开查看全部

相关问题