Solved

Why isn't this form centered?

Posted on 2013-06-21
5
241 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
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).

831 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