列引导中的中心div

时间:2015-06-24 12:26:45

标签: html css twitter-bootstrap multiple-columns

我试图将表单放在bootstrap中的列中。是否有可能,因为我搜索了一个多小时但仍未找到任何结果。我是bootstrap的新手...

我的代码:

<div class="container-fluid">

    <!--Row with two equal columns-->

    <div class="row">

        <div class="col-sm-8">

        <form class="form-inline row" role="form" action="index.php" method="post">

                <input class="form-control" type="text" name="kerkim" id="input_main" value="">

                <i id="slash">|</i>

                <div class="input-group">

                <input id="address" class="form-control" type="text" >
                <div class="input-group-btn">
                <button type="text" class="btn btn-warning"><i>Me gjej</i></button>
                </div>
                </div>
                    <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i></button>

            </form>
        </div>

        <div class="col-sm-2"><h3>Second left</h3></div>
        <div class="col-sm-2"><h3>Second right</h3></div>

3 个答案:

答案 0 :(得分:3)

添加一个类来形成&#34; center_form&#34;

    <form class="form-inline row center_form" role="form" action="index.php" method="post">

并在下面添加css

    .center_form{margin:0 auto;}

答案 1 :(得分:2)

您可以使用col-md-offset-4

形式的偏移值
<form class="form-inline row col-md-offset-4" method="post" action="index.php" role="form">

有关详情,请参阅 LINK

答案 2 :(得分:0)

您需要从表单元素中删除类行,因为它不包含任何列。接下来,您需要使用CSS来使表单居中。 试试这个:

HTML

<div class="container-fluid">

    <!--Row with two equal columns-->

    <div class="row">

        <div class="col-sm-8">

        <form class="form-inline centered" role="form" action="index.php" method="post">

                <input class="form-control" type="text" name="kerkim" id="input_main" value="">

                <i id="slash">|</i>

                <div class="input-group">

                <input id="address" class="form-control" type="text" >
                <div class="input-group-btn">
                <button type="text" class="btn btn-warning"><i>Me gjej</i></button>
                </div>
                </div>
                    <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i></button>

            </form>
        </div>

        <div class="col-sm-2"><h3>Second left</h3></div>
        <div class="col-sm-2"><h3>Second right</h3></div>
    </div>
</div>

CSS

.centered {
    margin: auto;
}

或者,您可以使用此html布局来完成居中的表单:

<div class="container-fluid">

    <!--Row with two equal columns-->

    <div class="row">

        <div class="col-sm-8">
        <div class="row">
        <form class="form-inline centered col-sm-8 col-sm-offset-2" role="form" action="index.php" method="post">

                <input class="form-control" type="text" name="kerkim" id="input_main" value="">

                <i id="slash">|</i>

                <div class="input-group">

                <input id="address" class="form-control" type="text" >
                <div class="input-group-btn">
                <button type="text" class="btn btn-warning"><i>Me gjej</i></button>
                </div>
                </div>
                    <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i></button>

            </form>
        </div>

        <div class="col-sm-2"><h3>Second left</h3></div>
        <div class="col-sm-2"><h3>Second right</h3></div>
        </div>
    </div>
</div>