Having trouble aligning the form in the center?

Despite #container being centered, I am struggling to center the <form>. It is important for me to have all elements inside the form aligned horizontally and despite trying various techniques, it is not working as expected.

<!-- Container Start -->
<div id="container">
  <h1 class="signup-header-text">SIGN UP</h1>
  <div class="clear"></div>
  <form class="signup-form" action="#" method="post">
    <div id="first_step">
      <div class="form">
        <label for="gender">You are:</label>
        <br />
        <select id="gender" name="gender" size="2">
          <option value="1">Male</option>
          <option value="2">Female</option>
        </select>
        <div class="clear"></div>
      </div>
      <div class="clear"></div>
      <input class="submit" type="submit" name="submit_first" id="submit_first" value="" />
    </div>
  </form>
<div id="progress_bar">
       <div id="progress"></div>
       <div id="progress_text">0% Complete</div>
</div>
</div>
<!-- Container End -->

This snippet from my CSS:

#container {
    height: 410px;
    min-height: 410px;
    min-width: 756px;
    width: 756px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -205px; /* Half the height */
    margin-left: -378px; /* Half the width */
    background: #e9e5e5;
    border: solid #dcdcdc 2px;
    outline: solid #c4c4c4 1px;
    -webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    -moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
}

Answer №1

Added the style text-align: center;

#container {
height: 410px;
min-height: 410px;
min-width: 756px;
width: 756px;
overflow: hidden;
position: absolute;
top: 50%;
left: 50%;
margin-top: -205px; /* Half of the height */
margin-left: -378px; /* Half of the width */
background: #e9e5e5;
border: solid #dcdcdc 2px;
outline: solid #c4c4c4 1px;
-webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
-moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
text-align: center;
}​

View the example code on jsFiddle

Answer №2

To perfectly align your text in the center, follow these steps:

#container {
    height: 410px;
    min-height: 410px;
    min-width: 756px;
    width: 756px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    **text-align:center;**
    margin-top: -205px; /* Half the height */
    margin-left: -378px; /* Half the width */
    background: #e9e5e5;
    border: solid #dcdcdc 2px;
    outline: solid #c4c4c4 1px;
    -webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    -moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
}

Answer №3

Give this a shot:

.registration-form {
    justify-content: center;
}

Answer №4

To center the desired element, specify a width and apply margin: 0 auto.

.signup-form {
  margin: 0 auto;
  width: 100px;
}

http://jsfiddle.net/EXLSJ/

If you prefer not to set a fixed width, refer to this guide for 'shrinkwrapping' your container: How to make div not larger than its contents?

Answer №5

insert

justify-content:center;
align-items:center;
clear:both;

can also be used with left and right alignments

Answer №6

Include the following CSS code to align text in the center:

 #container {
 height: 410px;
 min-height: 410px;
 min-width: 756px;
 width: 756px;
 overflow: hidden;
 position: absolute;
 top: 50%; left: 50%;
 margin-top: -205px; /* Half the height */
 margin-left: -378px; /* Half the width */
 background: #e9e5e5;
 border: solid #dcdcdc 2px;
 outline: solid #c4c4c4 1px;
 -webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
 -moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
 box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
 **text-align: center;**
 }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with plain CSS animation not functioning in NextJS with Tailwind CSS

I found this amazing animation that I'm trying to implement from this link. After moving some of the animation code to Tailwind for a React Component, I noticed that it works perfectly in Storybook but fails to animate when running in next dev. It si ...

Modify the collapse orientation in Bootstrap

I would like the button to expand from the bottom when clicked and collapse back down, instead of behaving like a dropdown. <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

Storing data in a text or HTML file using server-side JavaScript

Currently, I am working on a JavaScript form that involves saving user-entered variables to either a .txt file or a new webpage with the variables pre-filled in the inputs. I know that JavaScript cannot directly manipulate the user's machine, but I am ...

Attempting to fill up a database table using a php iteration

My task is to populate a database table with more than 1,000 rows of data consisting of randomly generated numbers. Here is the code I am using: $input = new Card($request->all()); $i = 1; while($i <= 1000 ){ $input->pin = intval( ...

Tips for designing a user interface for a security software product

We have created a cutting-edge security tool that can detect unauthorized network traffic. The user interface for displaying alerts is generated by a Java Servlet page. Currently, the page functions as a sophisticated console log. It features a large text ...

Implementing microdata without visibly displaying tagged entities on the webpage

I have a query regarding the implementation of Microdata on my webpage where tagged entities are not being displayed. For instance, I want to talk about two individuals in a paragraph without their names appearing on the webpage. Is there a method to only ...

Utilize various CSS styles for individual sections within a multi-page website

Having a web page with multiple subpages each having their own specific CSS can be quite challenging. Sometimes, when all the CSS files are applied globally, they tend to mix with each other causing a headache for developers. One common approach is to decl ...

Hover over the Div element for inline effect

Hello all, I am currently working on running a while loop from a database to show different records. The twist is that these records are displayed as images, which makes it tricky to customize using standard CSS. To work around this, I'm implementing ...

The website flickers in and out as it loads

My site keeps flashing whenever it loads. Despite trying the solutions recommended in this stackoverflow post, I have had no success. Every page on my website loads a nav.html file using this code: $.get("nav.html", function(data){     $("#nav-placeho ...

What is the process for clearing the input value of a View from another View?

My situation seems simple and straightforward, yet I am struggling to achieve the desired output. In this scenario, I have two HTML pages named Index.htm and Main.htm, as well as a script page named mscript.js. Index.htm contains a button (Clear), and Mai ...

Managing numerous range sliders in a Django form

My Request: I am looking to have multiple Range sliders (the number will change based on user selections) on a single page. When the sliders are moved, I want the value to be updated and displayed in a span element, as well as updating the model. The Issu ...

Compel the browser to initiate a reflow by adjusting the CSS

I am currently in the process of building a responsive image slider without relying on jQuery, using CSS3 transitions. The setup is quite simple: there's a viewport with a UL inside, containing relatively positioned LIs that are left floated. Howeve ...

Having difficulty incorporating a video into the background

After searching online and attempting two different methods, I am still unable to achieve the desired result. I want a video to cover the entire background of my webpage. Here is what I have tried: CSS - video#bgvid { position: fixed; top: 50%; ...

Utilizing PHP to Extract Information through cURL and HTML Parsing

Is there a way to search through an HTML page specifically for text contained within a particular div element? ...

Partially Assessed Ajax Response

I am struggling with my ajax response as it seems to evaluate only some of the html, but not all of it. For instance, I have this code that replaces a div with the response from the request: eval(document.getElementById("test").innerHTML-xmlhttp.response ...

Quickly switch between pages as they load

In Chrome, I'm experiencing a white flash between page loads that is causing transitions to appear choppy. I've taken various steps to optimize the site, such as using image sprites, reducing image sizes, minifying CSS, ensuring correct CSS loadi ...

The synchronization issue between ng-class and animation

I'm experiencing a strange issue with ng-class and suspect that it may be related to a race condition. Here is the example on Plunker: example Below is the relevant JavaScript code: self.slideLeft = function() { if (self.end_index < se ...

Utilizing jQuery to apply a class to an element and modify the CSS parameters with custom values simultaneously

Unsure if this idea is feasible, but I'll attempt to explain my requirements. I am interested in accomplishing something like the following: A CSS class with variables X, Y, and Z left undefined: .r {border-radius:Xpx;-webkit-border-radius:Ypx;-moz ...

Run the function after the onclick function has finished executing

I'm currently working on diagnosing an issue with this application. There is an anchor tag that contains the following code: onclick="javascript: return ShowItemDiscussion();" This code is located in a separate JavaScript file. I am attempting to ...

Evaluating the criteria and presenting two distinct notifications with setCustomValidity

When validating text fields in an HTML form, I am looking to check two conditions. Currently, the code below checks if the phone number entered is in the correct format and displays a message 'Enter a valid mobile number' if it is incorrect using ...