Centering all HTML form elements using CSS

css, forms, html

Solution

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.

Problem

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; } ```

Original source

Related problems