How to center align button in Semantic UI React?
Asked Answered
B

4

9

how can I center align a button in Semantic UI React
I have tried several approaches, using Grid, Grid Row, but no success

import {Segment, Button,Label,Sticky,Grid,Container} from 'semantic-ui-react';
import React, {Component} from 'react';

const GeneralSupportSegment =() => (
    <Segment>
         <Label  ribbon color="blue"  size="large">Support</Label>
         <Button>contact us</Button>
    </Segment>
);

export default GeneralSupportSegment;
Beadle answered 19/1, 2019 at 8:4 Comment(0)
L
12

Would be nice if you could share what you tried to do.

One solution might be:

<Segment>
  <Label ribbon color="blue" size="large">Support</Label>
  <Grid>
    <Grid.Column textAlign="center">
      <Button>contact us</Button>
    </Grid.Column>
  </Grid>
</Segment>

You can see it working here: https://codesandbox.io/s/z2pkv0ro43

Lymphosarcoma answered 19/1, 2019 at 8:45 Comment(2)
Is there not a simpler solution that doesn't require to add a grid?Weeping
The point is why it is not aligned center. We can center it by wrapping it with other things.Pediatrics
B
4

This one worked for me, without using Grid

<Segment>
    <Label ribbon color="blue" size="large">Support</Label>
    <Segment basic textAlign={"center"}>
        <Button style={{textAlign: "center"}}>contact us</Button>
    </Segment>
</Segment>
Bakke answered 21/7, 2019 at 11:21 Comment(0)
W
1

I found the code below to be a cleaner solution that doesn't require to add Grid from semantic-ui. The only thing was that I used the button within my register/sign up form. May not work for everyone.

What I did was add a

className: 'signUpBtn'

and then within my css file I added the

display:flex;

justify-content:center;

JSX:

<Form.Field className="signUpBtn" color="blue" control={Button}> Register </Form.Field>

CSS:

.signUpBtn {
   display: flex;
   justify-content: center;
}
Weeping answered 1/2, 2019 at 19:11 Comment(0)
P
0

Here is the simplest solution I have:

Previous code of icon inside a button(not aligned in the centre):

<Button>
    <Icon name="plus"/>
</Button>

Updated code(icon aligned at center):

<Button>
    <div>
        <Icon name="plus"/>
    </div>
</Button>
Pediatrics answered 29/12, 2020 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.