简体   繁体   English

与 React-Bootstrap 对齐

[英]Alignment with React-Bootstrap

I am fairly new to React-Bootstrap (and front-end work in general).我对React-Bootstrap (以及一般的前端工作)还很陌生。 What is the best practice for aligning elements when using React-Bootstrap?使用 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/ https://jsfiddle.net/f9vdksnu/1/

How do I align the Button component neatly to the Input component?如何将 Button 组件整齐地对齐到 Input 组件? 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.除了解决这个特殊问题外,我还对有关与 React-Bootstrap 保持一致的最佳实践的指示感兴趣。

Technically your both the col are aligned next to each other perfectly.从技术上讲,您的两个 col 彼此完美对齐。

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.如果从代码中删除label="Filter" ,您可以看到正确的对齐方式。

The only way I see it now is to give a margin-top: 25px;我现在看到的唯一方法是给一个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.基本上,我为按钮提供了一个自定义类,并在 css 中添加了对齐它所需的边距。

Add this one.加这个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM