CSS Bootstrap:带有错误消息的内联表单

时间:2014-07-12 10:03:30

标签: html css twitter-bootstrap

我正在使用Bootstrap v3.2。我有一个内联表单,但我想显示一条错误消息,但它不好: http://i.imgur.com/BCM6bZH.png

有没有办法做到这一点: enter image description here

HTML:

<div class="jumbotron">
    <p class="lead">{{errorMsg}}</p>
    <form class="form-inline" role="form" name="loginForm">
        <div class="form-group">
            <input class="form-control" ng-model="user.name" type="text" placeholder="Gebruikersnaam" required>
            <div>
                <span style="float:left" class="glyphicon glyphicon-warning-sign"></span>
            </div>
        </div>
    <div class="form-group">
      <input type="password" class="form-control" ng-model="user.password" placeholder="Wachtwoord" required>
    </div>
        <button onclick="javascript:void(0)"class="btn btn-default" ng-disabled="loginForm.$invalid" ng-click="login()">Log in</button>
    </form>
</div>

问题是输入上升了,我不想要。

2 个答案:

答案 0 :(得分:1)

请尝试使用此代码段

<强> HTML:

<div class="jumbotron">
    <p class="lead">{{errorMsg}}</p>
    <form class="form-inline" role="form" name="loginForm">
        <div class="form-group">
            <input class="form-control" ng-model="user.name" type="text" placeholder="Gebruikersnaam" required>
            <div>
                <span class="glyphicon glyphicon-warning-sign error-sign"></span>
            </div>
        </div>
    <div class="form-group">
      <input type="password" class="form-control" ng-model="user.password" placeholder="Wachtwoord" required>
    </div>
        <button onclick="javascript:void(0)"class="btn btn-default" ng-disabled="loginForm.$invalid" ng-click="login()">Log in</button>
    </form>
</div><div class="jumbotron">
    <p class="lead">{{errorMsg}}</p>
    <form class="form-inline" role="form" name="loginForm">
        <div class="form-group has-warning has-feedback">
          <label class="control-label sr-only" for="username">Gebruikersnaam</label>
          <input class="form-control" ng-model="user.name" id="username" placeholder="Gebruikersnaam" required="" type="text">
          <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
        </div>
        <div class="form-group">
          <input class="form-control" ng-model="user.password" placeholder="Wachtwoord" required="" type="password">
        </div>
        <button onclick="javascript:void(0)" class="btn btn-default" ng-disabled="loginForm.$invalid" ng-click="login()">Log in</button>
    </form>
</div>

CSS:

.form-inline .form-group {
    vertical-align: top;
}

.error-sign {
    float:left;
    margin-top: 7px;
}

您可以看到here

答案 1 :(得分:0)

这对我有用..

<div class="jumbotron">
    <p class="lead">{{errorMsg}}</p>
    <form class="form-inline" role="form" name="loginForm">
        <div class="form-group has-warning has-feedback">
          <label class="control-label sr-only" for="username">Gebruikersnaam</label>
          <input class="form-control" ng-model="user.name" id="username" type="text" placeholder="Gebruikersnaam" required>
          <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
        </div>
        <div class="form-group">
          <input type="password" class="form-control" ng-model="user.password" placeholder="Wachtwoord" required>
        </div>
        <button onclick="javascript:void(0)" class="btn btn-default" ng-disabled="loginForm.$invalid" ng-click="login()">Log in</button>
    </form>
</div>

我也做了一个bootply:http://www.bootply.com/BtRzVTdeTU