The element remains stationary and does not shift positions

My form is not centralizing properly, it seems to be stuck to the left side of #wrapper. I've tried adjusting margin-top but it doesn't seem to affect its horizontal position at all. I've played around with different values for margin and even tried using margin-left, but nothing seems to work. I followed a YouTube tutorial step by step, so I'm not sure where I went wrong. Does anyone have any suggestions?

body {
  padding: 0;
  margin: 0;
  background-color: #ccc;
}

#wrapper {
  width: 1000px;
  background-color: #FFF;
  margin: 0px auto;
  min-height: 400px;
  margin-top: 40px;
  border: 1px solid #999;
  border-bottom: 3px solid #999;
  border-radius: 5px;
}

#formDiv {
  width: 200px;
  margin: 0px auto;
  margin-top: 20px;
}
<!DOCTYPE html>
<html>
<head>
  <title>Registration Page</title>
  <link rel="stylesheet" href="css/styles.css" />
</head>
<body>
  <div id="wrapper">
    <div id="formDiv"></div>
    <form method="POST" action="index.php" enctype="multipart/form-data">
      <label>First Name:</label><br>
      <input type="text" name="fname" /> <br/><br/>
      <label>Last Name:</label><br>
      <input type="text" name="lname" /> <br/><br/>
      <label>Email:</label><br>
      <input type="text" name="email" /> <br/><br/>
      <label>Password:</label><br>
      <input type="*password" name="password" /> <br/><br/>
      <label>Image:</label><br>
      <input type="file" name="image" /> <br/><br/>
      <input type="submit" name="submit" />
    </form>
  </div>
</body>
</html>

Answer №1

Your formdiv tag was closed too early. Here is the corrected code:

<html>

<head>
    <title>Registration Page</title>
    <link rel="stylesheet" href="css/styles.css" />
</head>

<body>

    <div id="wrapper">

    <div id="formDiv">

    <form method="POST" action="index.php" enctype="multipart/form-data">

    <label>First Name:</label><br>
    <input type="text" name="fname" /> <br/><br/>

    <label>Last Name:</label><br>
    <input type="text" name="lname" /> <br/><br/>

    <label>Email:</label><br>
    <input type="text" name="email" /> <br/><br/>

    <label>Password:</label><br>
    <input type="password" name="password" /> <br/><br/>

    <label>Image:</label><br>
    <input type="file" name="image" /> <br/><br/>

    <input type="submit" name="submit" /> 

    </form>


    </div>
    </div>
    </body>


    </html>

Answer №2

To ensure proper center alignment, the form element must be centered as well

#container form{
      width: 200px;
    margin: 0 auto;
}

http://jsfiddle.net/64hz3abc/

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

Using Mat-Error for Two Way Binding leads to frequent triggering of ngModelChange事件

I am working with a mat input field that has two-way data binding using ngModel, and I want to add validation using mat-error and formControl. <mat-form-field [formGroup]="myForm"> <input matInput formControlName="myFormName" autocomplete="off" ...

Implement a dynamic card display using Bootstrap to ensure optimal responsiveness

Does anyone know how to create a card view using Bootstrap in HTML and CSS? https://i.sstatic.net/3hIsf.png I've been trying to replicate the image above with no success. Here is the code I have so far: <link href="https://stackpath.bootstrap ...

An issue occurred while calling the Selenium web driver: the driver.get() function couldn't access the attribute "href" of the linked_url, resulting in a stale element reference

Currently, I am utilizing Python with Selenium to work on extracting links from Google search results. After successfully accomplishing this task, I am now attempting to navigate through these links one by one using a for loop and the driver.get() method: ...

What is the best way to use Jquery to enclose a portion of a paragraph text within a

How can I wrap the content inside a span that comes after another span, inside a paragraph and a new span? To further illustrate this, consider the following example: <p>foo <span>bar</span> baz</p> The desired outcome is: <p& ...

Adjusting Image Size According to Window Resize?

My current issue involves having four images displayed side by side. When the window size is adjusted or viewed on a smaller device, the layout shifts to a line jump (with three images in a row and the fourth one below). What I actually want is for all fou ...

What is preventing me from modifying the input file name in PHP?

After executing the code below, an error message pops up: "Notice: Undefined index: uploadFile in C:\xampp\htdocs\ImageTest\processImage.php on line 17" However, when I switch every occurrence of 'uploadFile' with 'fi ...

The jQuery function .val()/.text() is unable to retrieve information from a particular section of HTML

Implementing HandlebarsJS with PHP and Yii to generate a page. Here is a snippet of the html/handlebars code on the page {{#if embed_link}} <p class='f_hidden_p'> <a href='{{embed_link}}'> {{ ...

Tips for creating incremental progress on a pop-up page?

I am looking for guidance on creating a page with specific functionalities. Here is what I have in mind: I want to implement a button that opens a popup when clicked. The popup should display static instructions and buttons for the user to progress throu ...

Difficulty encountered in positioning a div element

I have been attempting to align the div with class bioDiv under the image, but despite various attempts, I find myself feeling more and more confused. Can someone please review the code for me and offer a clue? I want to retain the same appearance, just re ...

SweetAlert html is not recognizing ng-app, but it functions correctly within the html body

When inserting a bootstrap table inside a SweetAlert, I encountered an issue where using ng-app or ng-repeat to populate data inside the table's rows did not call ng-app. However, when populating the table outside of the SweetAlert in the body, ng-app ...

Use a for loop to iterate through elements and retrieve input values using getElementById()

As I work through a for loop in JavaScript, I am utilizing the getElementById() method to fetch multiple input values. To begin, I dynamically created various input boxes and assigned distinct id's using a for loop. Subsequently, I am employing anoth ...

Update the div without altering its contents

Hello, I have a webpage where I am utilizing multiple select lists sourced from 4 different XML files. There is a function that updates one specific div by loading an XML file using the PHP command "$scripts = simplexml_load_file($link);" and then applies ...

Expanding Issue with Bootstrap Navigation

Hello! I am experiencing an issue with my navbar. The menu collapses, but it does not expand. I have used an example from Bootstrap and made some tweaks, but for some reason, it still doesn't expand properly. Below is the code that I have been workin ...

Combine jQuery and CSS to create a scrollable and extended fixed header

I am experiencing an issue where the header is fixed when scrolled down, but when I scroll back up to the top, it detaches and becomes unfixed again. How can I make the header stay fixed for a prolonged period of time? Are there any specific adjustments I ...

Interactive html5 canvas game with swiping mechanism

Currently, I am in the research phase for a new HTML5 canvas game that I want to create as a personal project to enhance my skills. Surprisingly, I have not been able to find any valuable articles or tutorials online about creating swipe-based games. The ...

AngularJS using the ng-controller directive

I am presenting the following HTML code excerpt... <!DOCTYPE html> <html lang="en-US" ng-app> <head> <title>priklad00007</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angula ...

The video continues playing even after closing the modal box

I am facing an issue with my code where a video continues to play in the background even after I close the modal. Here is the code snippet: <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria- ...

Is it possible to extract a div from a third-party domain and showcase it on my website?

Trying to integrate content from my Veetle.com channel onto my personal website has proven to be quite the challenge. Initially, I attempted to modify an iframe with CSS to display only the schedule information, but encountered limitations due to using 3rd ...

Utilizing deployJava.runApplet for precise element targeting

After years of successfully maintaining an applet that utilizes the traditional: <script src="foo.js"></script> method for embedding a Java applet, we can no longer ignore the need for change. It's time to switch to: deployJava.runAppl ...

What could be causing the discrepancy in results between the first and second methods?

Implementing Weather Icons: const getWeatherIcon = (iconParameter) => { const icon = `https://openweathermap.org/img/wn/${iconParameter}@2x.png` return <img src={icon} alt={iconParameter} /> } <div className="weathericon"> ...