Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alignment with React-Bootstrap

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.

Screenshot

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

like image 484
Roy van der Valk Avatar asked Jan 05 '16 11:01

Roy van der Valk


People also ask

How align items in Bootstrap react?

Use align-self utilities on flexbox items to individually change their alignment on the cross axis (the y-axis to start, x-axis if flex-direction: column ). Choose from the same options as align-items : start , end , center , baseline , or stretch (browser default). Responsive variations also exist for align-self .

How do you align in react?

js, set its display property to flex and its alignItems and justifyContent properties to center . The div's content will be horizontally and vertically centered. Copied!

How do I right align Bootstrap?

Using .align-self-end is used to align a single item in a Flexbox to the right.


1 Answers

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.

like image 140
Ajey Avatar answered Sep 27 '22 03:09

Ajey