如何将第二行的第二列与Bootstrap中的同一第一列或第一行对齐?

时间:2016-06-08 06:18:03

标签: twitter-bootstrap twitter-bootstrap-3

如何将 Text1 标记为相同的位置 Text3 标签,如下所示: http://www.bootply.com/R2CkWnzZQq#。实际上,我不想使用自定义CSS调整Text3标签。以下是html代码:

<br class="clearfix">
<div class="panel panel-default">
    <div class="panel-heading">
        <span class="panel-text-title">Header</span>
    </div>
    <div class="panel-body">
        <h2>Info</h2>
        <hr>
<div class="form-horizontal">
            <div class="col-sm-6">
                <div class="form-group">
                    <label for="name" class="col-sm-3 control-label">Text1</label>
                    <div class="col-sm-9">
                        <input class="form-control" id="Text" name="Text" value="" type="text">
                    </div>
                </div>

            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">Text2</label>
                    <div class="col-sm-9">
                        <input class="form-control" id="Text" name="Text" value="" type="text">
                    </div>
                </div>

            </div>
            <br class="clearfix">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="Report" class="col-sm-2 control-label">Text3</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" cols="20" id="Demo" name="Demo" placeholder="Text" rows="3" style="min-width:100%;"></textarea>
                    </div>
                </div>

            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="Description" class="col-sm-1 control-label"></label>
                    <div class="col-sm-11">
                        <button type="submit" class="btn btn-primary">Button</button>
                    </div>
                </div>
            </div>
</div>    </div>
</div>

提前致谢。

2 个答案:

答案 0 :(得分:1)

更改以下代码。我在您分享的链接上进行了测试,但它确实有效。干杯! : - )

<br class="clearfix">
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Report" class="col-sm-3 control-label">Text3</label>
                <div class="col-sm-9">
                    <textarea class="form-control" cols="20" id="Demo" name="Demo" placeholder="Text" rows="3" style="min-width:100%;"></textarea>
                </div>
            </div>

        </div>

我在这里所做的很简单,我将col-sm-12更改为col-sm-6以跟随热门标签,将col-sm-2 control-label更改为col-sm-3 control-label,将textarea div更改为{ {1}}至col-sm-10

编辑1 :摆弄div cols工作

col-sm-9

答案 1 :(得分:1)

使用以下

替换您的代码
<br class="clearfix">
<div class="panel panel-default">
    <div class="panel-heading">
        <span class="panel-text-title">Header</span>
    </div>
    <div class="panel-body">
        <h2>Info</h2>
        <hr>    
        <div class="row">
            <label for="name" class="col-sm-1 control-label text-right">Text1</label>
            <div class="col-sm-5">
                <input class="form-control" id="Text" name="Text" value="" type="text">
            </div>  
            <label for="name" class="col-sm-1 control-label text-right">Text1</label>
            <div class="col-sm-5">
                <input class="form-control" id="Text" name="Text" value="" type="text">
            </div>
        </div>
        <br class="clearfix">

        <div class="row">
        <label for="name" class="col-sm-1 control-label text-right">Text3</label>
            <div class="col-sm-11">
                <textarea class="form-control" cols="20" id="Demo" name="Demo" placeholder="Text" rows="3" style="min-width:100%;"></textarea>
            </div>
        </div>
        <br class="clearfix">

        <div class="row">
            <div for="name" class="col-sm-1"></div>
            <div class="col-sm-11">
                <button type="submit" class="btn btn-primary">Button</button>
            </div>
        </div>  
    </div>
</div>