html – Bootstrap水平表单不起作用

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

《html – Bootstrap水平表单不起作用》

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

<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>

最佳答案 你可以尝试这样:

<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>
点赞