使用bootstrap如何并排排列两个文本框

时间:2018-05-08 02:48:39

标签: html css twitter-bootstrap

enter image description here我在这里是新手请指导我如何安排textArea旁边的两个文本框

 <form class="form-horizontal">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-2 col-md-2">
                    <label>Fname</label>
                </div>
                <div class="col-sm-4 col-md-4">
                    <input type="text" class="form-control" placeholder="fname" />
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-2 col-md-2">
                <label class="control-label">comment</label>
            </div>
            <div class="col-sm-4 col-md-4">
                <textarea class="form-control" rows="5"></textarea>
            </div>
            <div class="col-sm-4 col-md-4">
                <label>Lastname</label>  <input type="text" class="form-control" placeholder="lname" /><br />
                <div class="col-sm-4 col-md-4">
                    <label>middlename</label>   <input type="text" class="form-control" placeholder="moddlename" />

                </div>

            </div>    
        </div>
    </form>

这里我想安排 LastName:TextBOx 在这个MiddleName下面:TextBox 这两个应该在textArea旁边

2 个答案:

答案 0 :(得分:1)

基本上你的嵌套网格可以获得更复杂的结构。 https://getbootstrap.com/docs/3.3/css/#grid-nesting

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

<div class="container">
 <form class="form-horizontal">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-2 col-md-2">
                    <label>Fname</label>
                </div>
                <div class="col-sm-4 col-md-4">
                    <input type="text" class="form-control" placeholder="fname" />
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-2 col-md-2">
                <label class="control-label">comment</label>
            </div>
            <div class="col-sm-4 col-md-4">
                <textarea class="form-control" rows="7" ></textarea>
            </div>
            <div class="col-sm-4 col-md-4">
                  <label>Lastname</label>  <input type="text" class="form-control" placeholder="lname" /><br/>
                  <label>middlename</label>   <input type="text" class="form-control" placeholder="moddlename" />
            </div>    
        </div>
    </form>         
</div>

</body>
</html>

答案 1 :(得分:1)

这可以通过将列数减少到两个并在姓氏标签上添加上边距来实现。我添加了内联,以便能够提供一大块代码,但它可以添加到您的CSS中。

<form>
    <div class="row">
        <div class="col-md-6">
            <label>First Name</label>
            <input type="text" class="form-control" placeholder="fname" />
            <label class="control-label">Comment</label>
            <textarea class="form-control" rows="6"></textarea>
        </div>
        <div class="col-md-6">
            <label style="margin-top: 100px">Last Name</label>  
            <input type="text" class="form-control" placeholder="lname" /><br />
            <label>Middle Name</label>   
            <input type="text" class="form-control" placeholder="moddlename" />
        </div>
    </div>
</form>