Bootstrap水平表单不起作用

时间:2017-09-23 02:16:45

标签: html css twitter-bootstrap

我试图为我的laravel应用程序构建一个带引导程序的简单水平表单。这是我正在使用的代码。但它显示如下:

form is displayed on the left halve of the page

表单显示在页面的左半部分。有任何想法吗?优选地,表格应该在页面上居中。



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<div class="container">
  <form class="form-horizontal">
    <fieldset>

      <!-- Form Name -->
      <legend>Register</legend>

      <!-- Text input-->
      <div class="form-group">
        <label class="col-sm-6 control-label" for="name">Name</label>
        <div class="col-sm-6">
          <input id="name" name="name" placeholder="Name" class="form-control input-md" required="" type="text">
        </div>
      </div>

      <!-- Text input-->
      <div class="form-group">
        <label class="col-sm-6 control-label" for="email">Email</label>
        <div class="col-sm-6">
          <input id="email" name="email" placeholder="Email" class="form-control input-md" required="" type="email">
        </div>
      </div>

      <!-- Password input-->
      <div class="form-group">
        <label class="col-sm-6 control-label" for="password">Password</label>
        <div class="col-sm-6">
          <input id="password" name="password" placeholder="Password" class="form-control input-md" required="" type="password">
        </div>
      </div>

      <!-- Password input-->
      <div class="form-group">
        <label class="col-sm-6 control-label" for="password_confirmation">Confirm Password</label>
        <div class="col-sm-6">
          <input id="password_confirmation" name="password_confirmation" placeholder="Re-enter Password" class="form-control input-md" required="" type="password">
        </div>
      </div>

      <!-- Button -->
      <div class="form-group">
        <label class="col-sm-6 control-label" for="submit"></label>
        <div class="col-sm-6">
          <button id="submit" name="submit" class="btn btn-primary">Register</button>
        </div>
      </div>

    </fieldset>
  </form>
</div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

您可以尝试这样:

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<div class="container">
<div class="row">
	<div class="col-lg-8 col-md-8">
		<form class="form-horizontal">
			<fieldset>
				<!-- Form Name -->
				<legend>Register</legend>

				<!-- Text input-->
				<div class="form-group">
					<label class="col-sm-6 control-label" for="name">Name</label>
					<div class="col-sm-6">
						<input id="name" name="name" placeholder="Name" class="form-control input-md" required="" type="text">
					</div>
				</div>

				<!-- Text input-->
				<div class="form-group">
					<label class="col-sm-6 control-label" for="email">Email</label>
					<div class="col-sm-6">
						<input id="email" name="email" placeholder="Email" class="form-control input-md" required="" type="email">
					</div>
				</div>

				<!-- Password input-->
				<div class="form-group">
					<label class="col-sm-6 control-label" for="password">Password</label>
					<div class="col-sm-6">
						<input id="password" name="password" placeholder="Password" class="form-control input-md" required="" type="password">
					</div>
				</div>

				<!-- Password input-->
				<div class="form-group">
					<label class="col-sm-6 control-label" for="password_confirmation">Confirm Password</label>
					<div class="col-sm-6">
						<input id="password_confirmation" name="password_confirmation" placeholder="Re-enter Password" class="form-control input-md"
							required="" type="password">
					</div>
				</div>

				<!-- Button -->
				<div class="form-group">
					<label class="col-sm-6 control-label" for="submit"></label>
					<div class="col-sm-6">
						<button id="submit" name="submit" class="btn btn-primary">Register</button>
					</div>
				</div>

			</fieldset>
		</form>
	</div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以尝试以下引导代码:

<div class="col-md-4 col-md-offset-4">your div</div>

所以,基本的想法是将所有列除以3意味着总共有12个自举列,如果将它除以4,它会给你3列。然后把你的div放在中间列。意思是col-md-4生成一列4个引导列。

试试这个:我尝试过使用IntelliJ Idea,它在浏览器中运行正常。让我知道什么不起作用?

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<div class="container">
    <form class="form-inline">
        <fieldset>
           <div class="col-md-4 col-md-offset-4">
            <!-- Form Name -->
            <legend>Register</legend>

            <!-- Text input-->
            <div class="form-group">
                <label class="col-sm-6 control-label" for="name">Name</label>
                <div class="col-sm-6">
                    <input id="name" name="name" placeholder="Name" class="form-control input-md" required="" type="text">
                </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
                <label class="col-sm-6 control-label" for="email">Email</label>
                <div class="col-sm-6">
                    <input id="email" name="email" placeholder="Email" class="form-control input-md" required="" type="email">
                </div>
            </div>

            <!-- Password input-->
            <div class="form-group">
                <label class="col-sm-6 control-label" for="password">Password</label>
                <div class="col-sm-6">
                    <input id="password" name="password" placeholder="Password" class="form-control input-md" required="" type="password">
                </div>
            </div>

            <!-- Password input-->
            <div class="form-group">
                <label class="col-sm-6 control-label" for="password_confirmation">Confirm Password</label>
                <div class="col-sm-6">
                    <input id="password_confirmation" name="password_confirmation" placeholder="Re-enter Password" class="form-control input-md" required="" type="password">
                </div>
            </div>

            <!-- Button -->
            <div class="form-group">
                <label class="col-sm-6 control-label" for="submit"></label>
                <div class="col-sm-6">
                    <button id="submit" name="submit" class="btn btn-primary">Register</button>
                </div>
            </div>
           </div>
        </fieldset>
    </form>
</div>

答案 2 :(得分:0)

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <div class="container">
      <form class="form-horizontal">
        <fieldset>

          <!-- Form Name -->
          <legend>Register</legend>

          <!-- Text input-->
          <div class="form-group">
            <label class="col-sm-3 control-label" for="name">Name</label>
            <div class="col-sm-6">
              <input id="name" name="name" placeholder="Name" class="form-control input-md" required="" type="text">
            </div>
          </div>

          <!-- Text input-->
          <div class="form-group">
            <label class="col-sm-3 control-label" for="email">Email</label>
            <div class="col-sm-6">
              <input id="email" name="email" placeholder="Email" class="form-control input-md" required="" type="email">
            </div>
          </div>

          <!-- Password input-->
          <div class="form-group">
            <label class="col-sm-3 control-label" for="password">Password</label>
            <div class="col-sm-6">
              <input id="password" name="password" placeholder="Password" class="form-control input-md" required="" type="password">
            </div>
          </div>

          <!-- Password input-->
          <div class="form-group">
            <label class="col-sm-3 control-label" for="password_confirmation">Confirm Password</label>
            <div class="col-sm-6">
              <input id="password_confirmation" name="password_confirmation" placeholder="Re-enter Password" class="form-control input-md" required="" type="password">
            </div>
          </div>

          <!-- Button -->
          <div class="form-group">
            <label class="col-sm-3 control-label" for="submit"></label>
            <div class="col-sm-6">
              <button id="submit" name="submit" class="btn btn-primary">Register</button>
            </div>
          </div>

        </fieldset>
      </form>
    </div>

col-sm-6 control-label =&gt; col-sm-3 control-label