Jump to content

Centering Buttons in a Form


DVigneault

Recommended Posts

Hey all--more trouble styling my forms.

 

Here's the HTML:

<div id="wrapper">
<form>
<fieldset>Some stuff</fieldset>
<div id="buttons">
<button>Submit</button>
<button>Reset</button>
</div>
</form>
</div>

 

And the CSS:

div#wrapper {
width: 800px;
margin-left: auto;
margin-right: auto;
}

#buttons {
display: inline;
margin-left: auto;
margin-right: auto;
}

 

I'd like for the "buttons" div to be centered within the 800px "parent" div, but instead it stays against the left side.  I can get it to look roughly how I want by setting margin-left to 300px or so, but I'd really just like it centered (and to know why setting the margins to auto isn't having the effect I thought it'd have).  Any ideas about what I'm doing wrong?

 

Best,

 

-d

Link to comment
https://forums.phpfreaks.com/topic/266025-centering-buttons-in-a-form/
Share on other sites

the buttons won't center because they are not block-level elements.  Much like a <span> that that only responds natively to font-based properties (size, iine-height). 

 

Anyway, you have it wrapped in a div, so just set the div to have centered text.

 

http://jsfiddle.net/svjVX/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.