Luis
Luis

Reputation: 5914

HTML fieldset, center not working

I want to center a fieldset but I want it to be resize due to its content, so I added the attr display: inline-block; to the style, which makes that, but it moves the fieldset to the left...

I was using margin: 0 auto; to center the fieldset but its not working anymore...

Here's an example

Upvotes: 1

Views: 4323

Answers (1)

David Thomas
David Thomas

Reputation: 253318

If you just add text-align: center; to your fieldset CSS rules, it seems to work (centering the labels against the inputs below).

JS Fiddle demo.


Edited

As it's the fieldset that needs to be centred, rather than its content, simply add the text-align: center; to the parent element of the fieldset. Normally this should be the form element (or a parent fieldset, since nesting is valid), but as there is no form in the linked example I've applied the text-align to the body element: updated JS Fiddle demo.

Upvotes: 3

Related Questions