How do I vertical center a label in a div?

Viewed 67365

I have a div with a height of 30px.

I want to add plain text to this div. How can I make the plain text appear on the center of my div? i.e, the text will be shown 15px under the top of the div.

I tried a label with margin-top: 15; but it didn't work.

9 Answers

Although this is an old thread, I think a flex solution should also be presented. If you style your div with

display: flex; 
align-items: center;

it should work

Codesandbox

Related