Solved

Why isn't this form centered?

Posted on 2013-06-21
5
245 Views
Last Modified: 2013-06-22
Hello,

I created a form that needs to be centered horizontally on the page.  But I'm not getting it quite right.  It's flush left.

Here's a link to the demo page:  Link to page with form.

Here's the css I am using unsuccessfully:
div#FormCentering {
width: 1011px;

}

form#chronoform_contactus {
width: 300px;
margin-left: auto ;
margin-right: auto ;
}

Open in new window

Looking forward to your solution...

Rowby
0
Comment
Question by:Rowby Goren
5 Comments
 
LVL 17

Assisted Solution

by:OmniUnlimited
OmniUnlimited earned 167 total points
ID: 39267508
Don't try and center the form.  Add text-align: center to div#FormCentering and enclose the form in a fixed width containing div with the left, right margins set to auto and that should do it.   You can set text-align: left on the containing div if you don't want the text in the text boxes centered.
0
 

Expert Comment

by:Nikc-Nack
ID: 39267534
I took a quick look at your site and it appears that your division is not getting the proper alignment. Look at your template.css file on line 286. That CSS file is getting priority over whatever CSS that you may be trying to include. In the CSS at that location the margin is being set to 0; which is causing the division not to be centered.
I usually do not try to style forms, I would personally recommend enclosing the form in a division and centering the division.

I believe that fixing the margins would solve the problem though. Let me know if that works out for you.

- Nikc
0
 
LVL 16

Assisted Solution

by:rbudj
rbudj earned 166 total points
ID: 39267952
A quick work around until you figure out the priority... Inline CSS takes priority so adding a width and a margin to the div will place it in the center. You do not want text-align. That is for text and images.

<div id="FormCentering" style="text-align: center; width:300px; margin:auto;">
center-form.jpg
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 167 total points
ID: 39268022
Yes the main problem is your form width it's very large that's why it's not centered. Just change your css to :

div#FormCentering {
    margin-left: auto;
    margin-right: auto;
    width: 300px;
}

Open in new window

0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 39268234
Hi

All of your comments and solutions were helpful not only in this form, but centering divs specifically.   So I have split the points.

And now my "form" fields are centered.

Thanks everyone for your help and insights.

Rowby
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question