skip to Main Content

I tried using md-offset-8, xs-2 but that didn’t work, I need to aligned all the form fields in center.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />

<div class="col-md-8 col-md-offset-4 text-center">
  <form class="form" action="/action.php", method="POST">
    <div class="form-group row">
      <div class="col-xs-4">
        <label for="field_1">Field 1</label>
        <input class="form-control" id="field_1" type="text" name="field 1">
      </div>
      <div class="col-xs-2">
        <label for="field_2">Field 2</label>
        <input class="form-control" id="field_2" type="text" name="field 2">
      </div>
    </div>
    <div class="form-group row">
      <div class="col-xs-8">
        <label for="dataFolder">Field 3</label>
        <input class="form-control" id="field_3" type="text" name="field_3" value=text>
      </div>
    </div>
    <div class="col-md-6 text-center">
      <button type="submit" class="btn ink-reaction btn-raised btn-primary">Save</button>
    </div>
  </form>
</div>

2

Answers


  1. Like so? you may need to adjust the position of the submit button in order to align all the elements vertically. A flex-box container could do the trick to do it

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
    
    <div class="col-md-8 col-md-offset-4 text-center">
            <form class="form" action="/action.php", method="POST">
                <div class="form-group row">
                    <div class="col-xs-3">
                        <label for="field_1">Field 1</label>
                        <input class="form-control" id="field_1" type="text" name="ip">
                    </div>
                    <div class="col-xs-2">
                        <label for="field_2">Field 2</label>
                        <input class="form-control" id="field_2" type="text" name="port">
                    </div>
                    <div class="col-xs-5">
                        <label for="dataFolder">Field 3</label>
                        <input class="form-control" id="field_3" type="text" name="field_3" value=text>
                    </div>
                <div class="col-md-2 text-center">
                    <button type="submit" class="btn ink-reaction btn-raised btn-primary">Save</button>
                </div>
                </div>
    
    
            </form>
        </div>
    Login or Signup to reply.
  2. Do u mean something like this?

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
    <div id="page" class="container">
      <div class="row">
          <div class="col-md-6 col-md-offset-3 text-center">
              <div class="form-group">
                  <label for="firstName">Filed 1:</label>
                  <input id="firstName" class="form-control text-center" type="text">
              </div>
              <div class="form-group">
                  <label for="lastName">Filed 2:</label>
                  <input id="lastName" class="form-control text-center" type="text">
                  <div class="form-group">
                    <label for="lastName">Filed 3:</label>
                    <input id="lastName" class="form-control text-center" type="text">
                  <button type="submit" class="btn ink-reaction btn-raised btn-primary">Save</button>
              </div>
          </div>
      </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search