-2

I have tried everything. I cannot get this centered on the screen. It just sits on the left of the webpage. Thank you for any help.

.form
{
    margin-top: 29px;
    margin-left: 130px;
    padding-top: 63px;
    padding-left: 350px;
    padding-right: 40px;
    background-image: url(form.png);
    background-repeat: no-repeat;
    height: 100px;
    width: 100px;
    position: center; 
    overflow: hidden;
}
<div class="allpage">
  <div class="header">
    <h1>»FORMULAR</h1>
  </div>
  <div class="form">
    <form action="/action_page.php">
      <label for="fname">Nume:</label><br>
      <input type="text" id="fname" name="fname" placeholder="Ion"><br>
      <label for="lname">Prenume:</label><br>
      <input type="text" id="lname" name="lname" placeholder="Popescu"><br>
    <input type="submit" value="Trimite">
  </form> 
</div>
David
  • 208,112
  • 36
  • 198
  • 279
jeffm
  • 1
  • 1

2 Answers2

0

You achieve this simply by using margin: auto. Furthermore: position: center isn't valid.

Working example:

I omitted margin-left and padding-left/-right because i think you tried to center the form with it.

.form {
  margin: auto;
  margin-top: 29px;
  padding-top: 63px;
  background-image: url(form.png);
  background-repeat: no-repeat;
  height: 100px;
  width: 100px;
  overflow: hidden;
}
<div class="allpage">
  <div class="header">
    <h1>»FORMULAR</h1>
  </div>
  <div class="form">
    <form action="/action_page.php">
      <label for="fname">Nume:</label><br>
      <input type="text" id="fname" name="fname" placeholder="Ion"><br>
      <label for="lname">Prenume:</label><br>
      <input type="text" id="lname" name="lname" placeholder="Popescu"><br>
      <input type="submit" value="Trimite">
    </form>
  </div>
</div>
biberman
  • 5,606
  • 4
  • 11
  • 35
-1

I have upgraded your styling, try this:

.form
{
    height: auto;
    width: 400px;
    margin: 0 auto;
    background: #333;
    text-align: center;
    border-radius: 5px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    font-family: Calibri;
}

.form input[type='text']{
  padding: 10px;
  width: 90%;
  margin: 2% 0;
  border: none;
}

.form input[type='submit']{
  padding: 10px;
  background: #0055E1;
  color: #fff;
  border: none;
  width: 95%;
  margin: 5% 0;
}
Aspect
  • 150
  • 11