Label on the left side instead above an input field

前端 未结 15 824
太阳男子
太阳男子 2020-12-02 09:44

I would like to have the labels not above the input field, but on the left side.

相关标签:
15条回答
  • 2020-12-02 09:56

    It seems adding style="width:inherit;" to the inputs works fine. jsfiddle demo

    0 讨论(0)
  • 2020-12-02 09:58

    You can use a span tag inside the label

      <div class="form-group">
        <label for="rg-from">
          <span>Ab:</span> 
          <input type="text" id="rg-from" name="rg-from" value="" class="form-control">
        </label>
      </div>
    
    0 讨论(0)
  • 2020-12-02 10:00
    <div class="control-group">
       <label class="control-label" for="firstname">First Name</label>
       <div class="controls">
        <input type="text" id="firstname" name="firstname"/>
       </div>
    </div>
    

    Also we can use it Simply as

    <label>First name:
        <input type="text" id="firstname" name="firstname"/>
    </label>
    
    0 讨论(0)
  • 2020-12-02 10:01

    You must float left all elements like so:

    .form-group,
    .form-group label,
    .form-group input { float:left; display:inline;   }
    

    give some margin to the desired elements :

     .form-group { margin-right:5px }
    

    and set the label the same line height as the height of the fields:

    .form-group label { line-height:--px; }
    
    0 讨论(0)
  • 2020-12-02 10:02

    Like this

    DEMO

    HTML

    <div class="row">
      <form class="form-inline">
        <fieldset>
          <label class="control-label"><strong>AB :</strong></label>
          <input type="text" class="input-mini" >
          <label class="control-label"><strong>BIS:</strong></label>
          <input type="text" class="input-mini" >
          <input type="button" value="Clear" class="btn btn-default btn-clear">
          <input type="submit" value="Los!" class="btn btn-primary">
        </fieldset>
      </form>
    </div>
    
    0 讨论(0)
  • 2020-12-02 10:04

    No CSS required. This should look fine on your page. You can set col-md-* as per your needs

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <div class="row">
                                <div class="col-md-12">
                                    <form class="form-inline" role="form">
                                        <div class="col">
                                            <div class="form-group">
                                                <label for="inputEmail" class="col-sm-3">Email</label>
                                                <input type="email" class="form-control col-sm-7" id="inputEmail" placeholder="Email">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                                <label for="inputPassword" class="col-sm-3">Email</label>
                                                <input type="password" class="form-control col-sm-7" id="inputPassword" placeholder="Email">
                                            </div>
                                        </div>
                                        
                                        <button class="btn btn-primary">Button 1</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-primary">Button 2</button>
                                    </form>
                                </div>
                            </div>

    0 讨论(0)
提交回复
热议问题