How do you center all form label and input fields using CSS?
How would you do this for a form with label text (block) on top of the input field?
#fieldset label {
display: block;
}
#fieldset input {
font-size: 0.8em;
height: 1.2em;
width: 15em;
}
As Boldewyn and Ben said, text-align will centre inline items (such as spans). To centre block elements (such as divs and forms and paragraphs), give it a width and set margin-right and margin-left to auto.
It's important to understand the difference between block and inline elements.
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