How to center form in twitter bootstrap?

后端 未结 6 811
悲&欢浪女
悲&欢浪女 2020-12-08 21:11
相关标签:
6条回答
  • 2020-12-08 21:52
    <div class="container">
    

    you coding for form

    </div>

    0 讨论(0)
  • 2020-12-08 21:53

    Nothing like good ol' CSS?

    .center > form {
      width: 300px; // some amount to prevent using 100% width
      margin: 0 auto;
    }
    

    And change .span6 to .span12

    Jsfiddle here. ​

    0 讨论(0)
  • 2020-12-08 22:00

    The native way for positioning elements in Bootstrap is using offset. I will assume that you are using a 12-column layout.

    Bootstrap 2

    <div class="container">
        <div class="row">
            <div class="span6 offset3">
                <form>
                    ...
                </form>
            </div>
        </div>
    </div>
    

    Further information in the documentation

    Bootstrap 3

    <div class="container">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <form>
                    ...
                </form>
            </div>
        </div>
    </div>
    

    Further information in the documentation

    0 讨论(0)
  • 2020-12-08 22:01

    This is where i found my answer.

    https://stackoverflow.com/a/15084576/1140407

    <div class="container">
      <div class="row">
        <div class="span9 centred">
          This div will be centred.
        </div>
      </div>
    </div>
    

    and to CSS:

    [class*="span"].centred {
      margin-left: auto;
      margin-right: auto;
      float: none;
    }
    
    0 讨论(0)
  • 2020-12-08 22:08

    Have you tried this?

    .center form {
            display: table;
            margin: 0 auto;
        }
    

    This is the easy and fast solution for me.

    0 讨论(0)
  • 2020-12-08 22:12

    Both answers posted are valid and work so I upvoted them. Here is another method i did not see posted.

    You can center your form by setting it to display:inline-block and center it within the .center container using text-align:center. This way the form will center regardless of width within that container:

    CSS

    .center {
        text-align:center;
    }
    
    .center form {
        display:inline-block;
    }
    
    0 讨论(0)
提交回复
热议问题