居中 div 列内 bootstrap
center div inside column bootstrap
我正在尝试将表单置于 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>
加一个class组成"center_form"
<form class="form-inline row center_form" role="form" action="index.php" method="post">
并在下面添加 css
.center_form{margin:0 auto;}
您可以使用 col-md-offset-4
形式的偏移值
<form class="form-inline row col-md-offset-4" method="post" action="index.php" role="form">
有关详细信息,请参阅 LINK
您需要从表单元素中删除 class 行,因为它不包含任何列。接下来,您需要使用 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>
我正在尝试将表单置于 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>
加一个class组成"center_form"
<form class="form-inline row center_form" role="form" action="index.php" method="post">
并在下面添加 css
.center_form{margin:0 auto;}
您可以使用 col-md-offset-4
<form class="form-inline row col-md-offset-4" method="post" action="index.php" role="form">
有关详细信息,请参阅 LINK
您需要从表单元素中删除 class 行,因为它不包含任何列。接下来,您需要使用 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>