引导程序

时间:2015-07-10 10:38:39

标签: twitter-bootstrap twitter-bootstrap-3

您好我是bootstrap的新手,我在格式化网格时遇到了一些问题。我希望我的电子邮件和密码字段具有水平格式。对于地址,我希望有一个更传统的布局。我该如何将两者结合起来?不幸的是,它被搞砸了我使用它的方式(因为Bootstrap写class="form-horizontal"需要进入<form>标签。但是afaik我只能使用一个表单来处理method = post。

    <!DOCTYPE html>
<html lang="De">
<head>
  <title>Titel</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h1>Titel</h1>
  <p>Bitte erfasse Deine persönlichen Angaben:</p>
  <form role="form" action="/registrieren" method="post">
    <div class="row">
            <div class="col-md-4">
                <label class="radio-inline"><input type="radio" name="gender">Frau</label>
                <label class="radio-inline"><input type="radio" name="gender">Mann</label>
                <label class="radio-inline"><input type="radio" name="gender">Anderes</label>
            </div>
    </div>
    <div class="row">
        <div class="col-md-2">
                <label for="usr">Vorname:</label>
                <input type="text" class="form-control" id="vorname" name="vorname">
        </div>
        <div class="col-md-2">
                <label for="usr">Name:</label>
                <input type="text" class="form-control" id="name" name="name">
        </div>
    </div>
    <div class="row">
        <div class="col-md-3">
                <label for="usr">Strasse:</label>
                <input type="text" class="form-control" id="strasse" name="strasse">
        </div>
    </div>
    <div class="row">
        <div class="col-md-1">
                <label for="usr">PLZ:</label>
                <input type="text" class="form-control" id="plz" name="plz">
        </div>
        <div class="col-md-2">
                <label for="usr">Ort:</label>
                <input type="text" class="form-control" id="ort" name="ort">
        </div>
    </div>
    <div class="form-horizontal">
        <div class="form-group">
            <label class="control-label col-sm-2"  for="usr">Email:</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" id="email" name="email">
                </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="pwd">Password:</label>
            <div class="col-sm-3">
                <input type="password" class="form-control" id="pwd" placeholder="Enter password">
            </div>
        </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </div>
    <br>
  </form>
</div>
</body>
</html>

这应该是它的样子:

enter image description here

1 个答案:

答案 0 :(得分:0)

您不需要将.form-horizo​​ntal添加到实际的<form>元素,您可以使用.form-horizo​​ntal类创建<div>并包装您想要的表单元素在其中有水平风格。

<form>
  <!-- Normal form inputs outside the div -->
  <div class="form-group">
     <label for="name">Name</label>
     <input type="text" name="name" id="name" class="form-control">
  </div>
  <div class="form-horizontal>
     <!-- Form inputs that you want to have horizontal layout -->
  </div>
</form>