1

This is my button. My button is not centered, and I can't seem to edit the text inside.

enter image description here

Other postings suggest putting a span around the button's content, which I did, but it doesn't seem to work. I tried changing the letters to be pink just to see if it would do anything, but it did not. Presumably, here also would be where I could fidget with the placement inside the button, no? Here is my code.

<Button bgColor="#609D64" style={{ marginTop: '-17px' }}>
    <span style={{ color: 'pink' }}>START
    </span>
</Button>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415

3 Answers3

1

You don't need the span. Try using flexbox.

I've added the styles

display: flex;
justify-content: center;
align-items: center;

This should make the text centered both vertically and horizontally.

<Button style={{ display: flex; justify-content: center; align-items: center; text-align: center; color: pink; background: #609D64; }}>START</Button>

btw it's not good to inline styles unless you really have to. also if this code doesn't fix you problem then please show what html Button outputs because it may be the rendered component is causing the problem.

Pixelomo
  • 6,373
  • 4
  • 47
  • 57
0

It should work for you.

<Button style="margin-top:-17px; background-color:#609D64; text-align:center">
<span style="color:pink">START
</span>
</Button>
4b0
  • 21,981
  • 30
  • 95
  • 142
0

This is a solution using flex. There is an inline-flex declaration –

button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 6px 12px;
  border: 1px solid #CDCDCD;
  background: #FFF;
  color: hotpink;
}
<p><button>hello world</button> Welcome to the water planet!</p>

This is an especially important detail to know when mixing flex into inline-block layouts.

UkFLSUI
  • 5,509
  • 6
  • 32
  • 47
CWebba1
  • 27
  • 6