Alignment with React-Bootstrap

断了今生、忘了曾经 提交于 2021-01-26 03:58:19

问题


I am fairly new to React-Bootstrap (and front-end work in general). What is the best practice for aligning elements when using React-Bootstrap?

For example:

<Grid>
    <Row className="show-grid">
        <Col md={10}>
          <Input type="text" label="Filter"/>
        </Col>
        <Col md={2}>
          <Button>Clear</Button>
        </Col>
      </Row>
</Grid>

https://jsfiddle.net/f9vdksnu/1/

How do I align the Button component neatly to the Input component? By default the button is aligned to the top.

Besides solving this particular issue I am interested in pointers on best practices on aligning with React-Bootstrap.


回答1:


Technically your both the col are aligned next to each other perfectly.

Since the input is inside the form group, it gets the extra height as compared to the "clear" button.

If you remove label="Filter" from your code you can see the proper alignment.

The only way I see it now is to give a margin-top: 25px; to the button.

Here is the Demo

Basically, I gave a custom class to the button and in the css I added the margin I needed to align it.




回答2:


Add this one.

<Row className="align-items-end">


来源:https://stackoverflow.com/questions/34610156/alignment-with-react-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!