0

I am making an app. And here I have an input box and a button. I want to center it. I tried using the center tag, it did not work. I tried using align-items:center still did not work. How to do this ??? Here is my program -



.form-inline {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
}

.form-inline label {
  margin: 5px 10px 5px 0;
}

.form-inline input {
  vertical-align: middle;
  padding: 10px;
  background: transparent;
  border: 1px solid #ddd;
}

.form-inline button {
  padding: 10px 20px;
  background: transparent;
  border-right: 1px solid #ddd;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  color: white;
  cursor: pointer;
}


        <form class="form-inline" action="/">
          <input id="email" placeholder="Enter email" name="email" />

          <button type="submit">Submit</button>
        </form>

How to achieve this ??? Pls help

Nagari
  • 11
  • 2

4 Answers4

2
**justify-content: center;**

.form-inline {
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    justify-content: center;
}
Jaswinder Kaur
  • 1,606
  • 4
  • 15
1

.formContainer {
  display: block;
  text-align: center;
}

.form-inline {
  display: inline-flex;
  align-items: center;
}

.form-inline label {
  margin: 5px 10px 5px 0;
}

.form-inline input {
  vertical-align: middle;
  padding: 10px;
  background: transparent;
  border: 1px solid #ddd;
}

.form-inline button {
  padding: 10px 20px;
  background: transparent;
  border-right: 1px solid #ddd;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  color: white;
  cursor: pointer;
}
<div class="formContainer">
  <form class="form-inline" action="/">
    <input id="email" placeholder="Enter email" name="email" />
    <button type="submit">Submit</button>
  </form>
</div>
Joseph
  • 691
  • 4
  • 18
1

form {
  display: flex;
  justify-content: center;
  align-items: center;
  
  /* Use this line if you have to add multiple elements */
  flex-direction: column;
}
<form class="form-inline" action="/">
  <div class="input-field">
    <input id="email" placeholder="Enter email" name="email" />
    <button type="submit">Submit</button>
  </div>
</form>
Salwa A. Soliman
  • 695
  • 1
  • 3
  • 13
1

Use the justify-content: center; to align it to the center

.form-inline {
  display: flex;
  justify-content: center;
  align-items: center;
}

.form-inline label {
  margin: 5px 10px 5px 0;
}

.form-inline input {
  vertical-align: middle;
  padding: 10px;
  background: transparent;
  border: 1px solid #ddd;
}

.form-inline button {
  padding: 10px 20px;
  background: transparent;
  border-right: 1px solid #ddd;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  color: black;
  cursor: pointer;
}
<form class="form-inline" action="/">
          <input id="email" placeholder="Enter email" name="email" />

          <button type="submit">Submit</button>
        </form>
Nazish
  • 11
  • 4