Bootstrap和Bootstrap-Select - Fit选择和其他元素到div宽度,100%宽度/高度

时间:2016-01-28 06:06:22

标签: css twitter-bootstrap google-maps select bootstrap-select

我遇到了各种各样的问题。

1)我正在使用Bootstrap-Select来获得具有搜索功能的现代选择框,但无论我尝试什么,我似乎无法选择填充col-span。

2)我将行拆分为2列:2(选择)和10(图像/地图),但除非我将宽度从100%更改为更小,否则它们会重叠并放在每个列的顶部其他,而不是左右。

3)每个图像(将被地图替换)设置为50%高度和100%宽度,但我仍然看到浏览器的滚动条,它也不是一个小的滚动空间。我想在没有滚动条的情况下将地图显示为完整的50%高度(每个,总共100%)。我有一种感觉需要考虑导航栏的高度吗?

为方便起见,请使用附带的jsFiddle! 添加边框仅用于列可见性,可以删除。

HTML

<div class="container" style="border: 1px solid red;">
  <div class="row">
    <div class="col-md-2" style="border: 1px solid blue;">
      <div class="form-horizontal">
        <select class="selectpicker col-sm-12" data-live-search="true" title="Routes">
          <option>1 Route A - WEST</option>
          <option>2 Route B - SOUTH</option>
          <option>2 Route B - NORTH</option>
          <option>3 Very Long Route Name C - SOUTH</option>
          <option>3 Very Long Route Name C - NORTH</option>
          <option>4 Route D - EAST</option>
          <option>4 Route D - WEST</option>
          <option>5 An Extremely Long Route Name E - SOUTH</option>
          <option>5 An Extremely Long Route Name E - NORTH</option>
        </select>
      </div>
      <div class="col-md-10 canvas" style="border: 1px solid lime;">
        <div>
          <img src="http://designreviver.com/wp-content/uploads/2014/11/410316.jpg" style="width:100%; height:50%;">
        </div>
        <div>
          <img src="http://designreviver.com/wp-content/uploads/2014/11/410316.jpg" style="width:100%; height:50%;">
        </div>
      </div>
    </div>
  </div>
</div>

CSS

html, body, .container, .row, .canvas {
  height: 100%;
}

.canvas {
  width: 100%;
  height: 100%;
}

.selectpicker {
  padding-left:5px;
  padding-right:5px;
}

.navbar {
  margin-bottom: 0 !important;
}

JSFiddle DEMO

1 个答案:

答案 0 :(得分:5)

使用bootstrap时 - 选择使用data-width =&#34; 100%&#34;使select选择填充它的父级空间,即bootstrap列。您也可以在初始化时通过javascript添加此选项。您可以在此处详细了解该选项和其他选项:https://silviomoreto.github.io/bootstrap-select/options/#core-options

当使用.container或.container-fluid时,请确保按顺序保留类:.container .row .col-x-x。混合使用额外的div可能会导致问题,这些div可能会成为您尝试保持特定大小的元素的父母。

这是一个伟大的引导类,用于图像.img-responsive。我建议你用它来拍照。您可以在此处详细了解:http://getbootstrap.com/css/#images

这是一个更新的小提琴https://jsfiddle.net/mrLsveLf/3/

<强> HTML

<nav class="navbar navbar-inverse navbar-static-top">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="">Brand</a>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>


    <div class="navbar-collapse collapse" id="navbar">
      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Sign in <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li>Hey!</li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>

<div class="container">
  <div class="row">
      <div class="col-xs-4">
         <select class="selectpicker" data-live-search="true" title="Routes" data-width="css-width">
            <option>1 Route A - WEST</option>
            <option>2 Route B - SOUTH</option>
            <option>2 Route B - NORTH</option>
            <option>3 Very Long Route Name C - SOUTH</option>
            <option>3 Very Long Route Name C - NORTH</option>
            <option>4 Route D - EAST</option>
            <option>4 Route D - WEST</option>
            <option>5 An Extremely Long Route Name E - SOUTH</option>
            <option>5 An Extremely Long Route Name E - NORTH</option>
          </select>
      </div>
    <div class="col-xs-8">
      <img class="img-responsive" src="http://designreviver.com/wp-content/uploads/2014/11/410316.jpg" style="width:100%;height:50%;">
      <img class="img-responsive" src="http://designreviver.com/wp-content/uploads/2014/11/410316.jpg" style="width:100%;height:50%;">
     </div>
</div>
</div>