【问题标题】:center div inside column bootstrap列引导程序内的中心 div
【发布时间】:2015-06-24 12:26:44
【问题描述】:

我正在尝试在引导程序的列中居中表单。是否有可能,因为我搜索了一个多小时但仍然一无所获。我是引导程序的新手...

我的代码:

<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>

【问题讨论】:

    标签: html css twitter-bootstrap multiple-columns


    【解决方案1】:

    您可以使用col-md-offset-4 形式的偏移值

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

    更多详情请联系LINK

    【讨论】:

      【解决方案2】:

      添加一个类以形成“center_form”

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

      并在css下面添加

          .center_form{margin:0 auto;}
      

      【讨论】:

        【解决方案3】:

        您需要从表单元素中删除类行,因为它不包含列。接下来,您需要使用 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>
        

        【讨论】:

          最近更新 更多