试图创建两个bootstrap模板coloumn

时间:2016-08-06 07:07:23

标签: html css twitter-bootstrap

我试图创建带有两个颜色的简单模板。这是我到目前为止所得到的

enter image description here

我使用bootstrap。现在我想问一下。为什么我的侧边栏位置会留下一些空间?

左侧使用此<div class="pull-left col-sm-7"></div>和我的右侧<div class="col-sm-5">

这是我的HTML代码

<div class="container">

     <div class="row">
        <div class="col-sm-12"><img class="headerimg" src=""></div>
    </div>
     <div class="row">
        <div class="col-sm-12"> 
            <nav class="navbar navbar-default">
                <div class="container">
                    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="http://localhost:84/jdih/">Home</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown 
                    <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</div>
</div>
<div class="col-md-7"> 
<img src="" class="img-responsive" style='float:left;width:200px;height:200px; margin-right:10px;'>
<p class="text-justify">Text <br>
Text
</p>
<p class="text-justify">
Text</p>
<p class="text-justify">
Text
</p>

<p class="text-justify">Text</p>

<p class="text-justify">Text<br>
Text<br>
Text</p>

<p class="text-justify">Text</p>

<p class="text-justify"><strong>Text</strong>.</p>
</div>


<div class="col-md-5 pull-right"> 
    <form class="form-horizontal">
        <div class="form-group"> 
            <div class="col-md-5">
                           <label>Jenis</label>

                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                        <div class="form-group"><div class="col-md-5">

                           <label>Kategori</label>
                                                        <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                          <div class="form-group"> 
                          <div class="col-md-5">
                           <label>Tahun</label>

                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                         <div class="form-group">
                            <div class="col-md-5">
                                <label>Cari Berdasarkan</label>
                                    <select class="form-control select2" name="parent">
                                         <option value="">Semua Jenis</option>
                                    </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-5">
                                <label>Kata Kunci</label>
                                    <input type="text" class="form-control">
                            </div>
                        </div>
                          <div class="form-group">
                            <div class="col-md-5">

                                    <input type="submit" class="btn pull-right btn-submit" value="Find">
                            </div>
                        </div>
    </form>
</div>

</div>

这是小提琴https://jsfiddle.net/hv4c9yhd/

那么你能告诉我如何让sidebar part填空空间吗?提前致谢

6 个答案:

答案 0 :(得分:0)

尝试使用

<div class="container-fluid">

而不是

<div class="container">

从容器中删除内容

或者可以用css删除容器边距和填充

答案 1 :(得分:0)

col-md-7col-md-5更改为col-xs-7 col-xs-5。这肯定会有所帮助。你的屏幕可能会特别小。

答案 2 :(得分:0)

试试这个:

&#13;
&#13;
.headerimg{
				width : 100%;
			}
&#13;
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<div class="container">

     <div class="row">
     	<div class="col-sm-12"><img class="headerimg" src=""></div>
  	</div>
     <div class="row">
     	<div class="col-sm-12"> 
        	<nav class="navbar navbar-default">
  				<div class="container">
   					<div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="http://localhost:84/jdih/">Home</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          		<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown 
          			<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</div>
</div>
<div class="col-md-7 " style="display:inline-block;"> 
<img src="" class="img-responsive" style='float:left;width:200px;height:200px; margin-right:10px;'>
<p class="text-justify">Text <br>
Text
</p>
<p class="text-justify">
Text</p>
<p class="text-justify">
Text
</p>

<p class="text-justify">Text</p>

<p class="text-justify">Text<br>
Text<br>
Text</p>

<p class="text-justify">Text</p>

<p class="text-justify"><strong>Text</strong>.</p>
</div>


<div class="col-md-5 pull-right"> 
	<form class="form-horizontal">
    	<div class="form-group"> 
        	<div class="col-md-5">
                           <label>Jenis</label>
                           
                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>
                            	
							</select>
		                    </div>
        	        	</div>
                        <div class="form-group"><div class="col-md-5">

                           <label>Kategori</label>
                                                        <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>
                            	
							</select>
		                    </div>
        	        	</div>
                          <div class="form-group"> 
                          <div class="col-md-5">
                           <label>Tahun</label>
                           
                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>
                            	
							</select>
		                    </div>
        	        	</div>
                         <div class="form-group">
                         	<div class="col-md-5">
                           		<label>Cari Berdasarkan</label>
                            		<select class="form-control select2" name="parent">
                           				 <option value="">Semua Jenis</option>
	                                </select>
		                    </div>
        	        	</div>
                        <div class="form-group">
                         	<div class="col-md-5">
                           		<label>Kata Kunci</label>
                            		<input type="text" class="form-control">
		                    </div>
        	        	</div>
                          <div class="form-group">
                         	<div class="col-md-5">
                           		
                            		<input type="submit" class="btn pull-right btn-submit" value="Find">
		                    </div>
        	        	</div>
    </form>
</div>

</div>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

如果您不想在双方都提供空格,则不应将container用于navbar。您可以使用此container下方的navbar(如您所愿)

<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
   <div class="row">

     <div class="row">
        <div class="col-sm-12"><img class="headerimg" src=""></div>
    </div>
     <div class="row">
        <div class="col-sm-12"> 
            <nav class="navbar navbar-default">
                <div class="container">
                    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="http://localhost:84/jdih/">Home</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown 
                    <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</div>
</div>
</div>


<div class="container">
<div class="row">
        <div class="col-sm-12"> 
</div>
</div>
<div class="col-md-7"> 
<img src="" class="img-responsive" style='float:left;width:200px;height:200px; margin-right:10px;'>
<p class="text-justify">Text <br>
Text
</p>
<p class="text-justify">
Text</p>
<p class="text-justify">
Text
</p>

<p class="text-justify">Text</p>

<p class="text-justify">Text<br>
Text<br>
Text</p>

<p class="text-justify">Text</p>

<p class="text-justify"><strong>Text</strong>.</p>
</div>


<div class="col-md-5 pull-right"> 
    <form class="form-horizontal">
        <div class="form-group"> 
            <div class="col-md-5">
                           <label>Jenis</label>

                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                        <div class="form-group"><div class="col-md-5">

                           <label>Kategori</label>
                                                        <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                          <div class="form-group"> 
                          <div class="col-md-5">
                           <label>Tahun</label>

                            <select class="form-control select2" name="parent">
                            <option value="">Semua Jenis</option>

                            </select>
                            </div>
                        </div>
                         <div class="form-group">
                            <div class="col-md-5">
                                <label>Cari Berdasarkan</label>
                                    <select class="form-control select2" name="parent">
                                         <option value="">Semua Jenis</option>
                                    </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-5">
                                <label>Kata Kunci</label>
                                    <input type="text" class="form-control">
                            </div>
                        </div>
                          <div class="form-group">
                            <div class="col-md-5">

                                    <input type="submit" class="btn pull-right btn-submit" value="Find">
                            </div>
                        </div>
    </form>
</div>

</div>
</body>

</html>

答案 4 :(得分:0)

我查看了你的代码,发现你在定义一个新类时可以使用div,这个类可以很容易地附加到上一个父div中,如下所示:

而不是:

<div class="form-group"> 
        <div class="col-md-5">

这样做会让你的代码很难让别人理解,这是不好的做法。您可以通过执行以下操作轻松解决此问题:

<div class ="form-group col-md-5">

您必须了解此语法,尤其是在处理代码或尝试理解其他人员代码时。基本上,这将类.form-group和类.col-md-5应用于此div元素。它简洁明了,使您的代码看起来更清晰,更容易理解。

我清理了你的代码并调整了一些东西。如果这有帮助,或者您需要我解释我更改/删除的特定部分,请告诉我。

<div class="container-fluid">
 <div class="row">
   <div class="col-sm-12"> 
      <img class="headerimg img-responsive" src="pic1 image">
        <nav class="navbar navbar-default">
                <div class="navbar-header">
          <a class="navbar-brand" href="#">Home</a>
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
     </div>

<!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
              <li><a href="#">Link</a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown<span class="caret"></span></a></li>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li role="separator" class="divider"></li>
                <li><a href="#">Separated link</a></li>
                <li role="separator" class="divider"></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </ul>
          </div><!-- /.navbar-collapse -->
        </nav>
    </div>`
</div>

<div class="col-md-4"> 
    <img src="" class="img-responsive" alt="picture2">
    <p class="text-justify">Text <br>Text</p>
    <p class="text-justify">Text</p>
    <p class="text-justify">Text</p>
    <p class="text-justify">Text</p>
    <p class="text-justify">Text<br>Text<br>Text</p>
    <p class="text-justify">Text</p>
    <p class="text-justify"><strong>Text</strong>.</p>
</div>


<div class="col-md-4 col-md-offset-4 pull-right"> 
    <form class="form-horizontal">
        <div class="form-group col-md-5"> 
          <label>Jenis</label>
          <select class="form-control select2" name="parent">
              <option value="">Semua Jenis</option>
          </select>
          </div>
      <div class="form-group col-md-5">
          <label>Kategori</label>
          <select class="form-control select2" name="parent">
              <option value="">Semua Jenis</option>
          </select>
      </div>
      <div class="form-group col-md-5">
          <label>Tahun</label>
          <select class="form-control select2" name="parent">
              <option value="">Semua Jenis</option>
          </select>
      </div>
      <div class="form-group col-md-5">
          <label>Cari Berdasarkan</label>
          <select class="form-control select2" name="parent">
              <option value="">Semua Jenis</option>
          </select>
      </div>
      <div class="form-group col-md-5">
          <label>Kata Kunci</label>
          <input type="text" class="form-control" place-holder="value">
      </div>
      <div class="form-group col-md-5">
          <input type="submit" class="btn btn-default" value="Find">
      </div>
  </form>
</div>`

以下代码直接回答了您的问题:

<div class="container-fluid">
...</div>
<div class="col-md-4 col-md-offset-4 pull-right">
...</div>

有很多方法可以让您的表单响应,其他一些响应包括。我只是想我会强调组织和适当使用div的重要性,并确保每个标签都有适当的结束标记。

答案 5 :(得分:-1)

将此类“row-no-padding”添加到“col-sm-7”和“col-sm-5”-divs的父div中,然后将此css:

添加
.row-no-padding > [class*="col-"] {
  padding-left: 0 !important;
  padding-right: 0 !important;
}