I have got tricky problem here. I'd like to vertical align my text inside a button
<button id="rock" onClick="choose(1)">Rock</button>
And here is my CSS
button {
font-size: 22px;
border: 2px solid #87231C;
border-radius: 100px;
width: 100px;
height: 100px;
color: #FF5A51;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
button:active {
font-size: 22px;
border: 2px solid red;
border-radius: 100px;
width: 100px;
height: 100px;
}
You can check it out here http://jsfiddle.net/kA8pp/ . I want to have the text on the bottom. Thank you very much!
EDIT: I can't explain it well so here is the picture of it :)
1 Select the text you want to center between the top and bottom margins. 2 On the Page Layout tab, click the Page Setup Dialog Box Launcher. 3 Select the Layout tab. 4 In the Vertical alignment box, click Center 5 In the Apply to box, click Selected text, and then click OK.
Use line-height to center it vertically. I usually use the same value as its height. Works only when you know the height. I set height to 0 and line-height to zero and this worked!
To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.
You can use line-height
to achieve your goal.
button {
font-size: 22px;
border: 2px solid #87231C;
border-radius: 100px;
width: 100px;
height: 100px;
color: #FF5A51;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
line-height: 150px;
overflow: visible;
}
http://jsfiddle.net/kA8pp/2/
You can use flexbox (check browser support, depending on your needs).
button {
display: inline-flex;
align-items: flex-end;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With