Bootstrap Checkbox与标签不符,在移动设备上更糟

时间:2019-02-03 19:50:21

标签: css twitter-bootstrap-3

我无法获得控件标签以对齐复选框输入。在移动设备上甚至更糟。我希望文字排成一行。我究竟做错了什么?我以为div丢失了或有什么东西,但是在任何其他输入下都可以正常工作。我尝试使用CSS调整边距,但现在都可以。任何帮助,将不胜感激。这是代码:

   
   <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
   <!DOCTYPE html>
        <html lang="en">
          <head>
          
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
           <title>Login</title>
        
        
        <style>
        form .line {
            margin-bottom: 5px;
        }
        p{
           margin-top: 20px;
        }
        
        </style>
        
        
         <div class="container">
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8">
                  
        
                  <div class="panel panel-default">
          <div class="panel-body">
         <form class="form-horizontal">
        <fieldset>
        
        <!-- Form Name -->
        <legend>Login</legend>
        
        
        
        
        
        
        
        <!-- Text input-->
        <div class="form-group line">
          <label class="col-md-4 control-label" for="identity">Username</label>  
          <div class="col-md-4">
          <input id="identity" name="identity" type="text" placeholder="Enter Username" class="form-control input-md">
            
          </div>
        </div>
        
        <!-- Password input-->
        <div class="form-group line">
          <label class="col-md-4 control-label" for="password">Password</label>
          <div class="col-md-4">
            <input id="password" name="password" type="password" placeholder="Enter Password" class="form-control input-md">
            
          </div>
        </div>
        
        <!-- Multiple Checkboxes (inline) -->
        <div class="form-group">
          <label class="col-md-4 control-label" for="remember">Remember Me</label>
          <div class="col-md-4">
            <label class="checkbox-inline" for="remember">
              <input type="checkbox" name="remember" id="remember" value="1">
              
            </label>
          </div>
        </div>
        
        <!-- Button -->
        <div class="form-group">
          <label class="col-md-4 control-label" for="submit"></label>
          <div class="col-md-4">
            <button id="submit" name="submit" class="btn btn-primary">Login</button>
            <p><a href="forgot_password"><!--?php echo lang('login_forgot_password');?--></a></p>
          </div>
        </div>
        
        </fieldset>
        </form>
        </div>
        
        
        
        </div>
        
                </div>
               
        
             </div>
                <div class="col-md-2"></div></div>


            <div id="push"></div>

1 个答案:

答案 0 :(得分:1)

您可以添加一些CSS样式来控制.checkbox-inline的位置

媒体查询将移动较小屏幕的复选框。

还要注意,我在最后一个.form-small上添加了类.form-group,以控制复选框在较小屏幕上的位置。

.checkbox-inline {
  top: -7px;
}

@media only screen and (max-width: 991px) {
  .checkbox-inline {
    top: -40px;
    right: -115px;
  }
  .form-small {
    margin-bottom: 0 !important;
    max-height: 20px;
  }
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
   <!DOCTYPE html>
        <html lang="en">
          <head>
          
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
           <title>Login</title>
        
        
        <style>
        form .line {
            margin-bottom: 5px;
        }
        p{
           margin-top: 20px;
        }
        
        </style>
        
        
         <div class="container">
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8">
                  
        
                  <div class="panel panel-default">
          <div class="panel-body">
         <form class="form-horizontal">
        <fieldset>
        
        <!-- Form Name -->
        <legend>Login</legend>
        
        
        
        
        
        
        
        <!-- Text input-->
        <div class="form-group line">
          <label class="col-md-4 control-label" for="identity">Username</label>  
          <div class="col-md-4">
          <input id="identity" name="identity" type="text" placeholder="Enter Username" class="form-control input-md">
            
          </div>
        </div>
        
        <!-- Password input-->
        <div class="form-group line">
          <label class="col-md-4 control-label" for="password">Password</label>
          <div class="col-md-4">
            <input id="password" name="password" type="password" placeholder="Enter Password" class="form-control input-md">
            
          </div>
        </div>
        
        <!-- Multiple Checkboxes (inline) -->
        <div class="form-group form-small">
          <label class="col-md-4 control-label" for="remember">Remember Me</label>
          <div class="col-md-4">
            <label class="checkbox-inline" for="remember">
              <input type="checkbox" name="remember" id="remember" value="1">
              
            </label>
          </div>
        </div>
        
        <!-- Button -->
        <div class="form-group">
          <label class="col-md-4 control-label" for="submit"></label>
          <div class="col-md-4">
            <button id="submit" name="submit" class="btn btn-primary">Login</button>
            <p><a href="forgot_password"><!--?php echo lang('login_forgot_password');?--></a></p>
          </div>
        </div>
        
        </fieldset>
        </form>
        </div>
        
        
        
        </div>
        
                </div>
               
        
             </div>
                <div class="col-md-2"></div></div>


            <div id="push"></div>