【问题标题】:How to create a Gmail like layout with Twitter Bootstrap如何使用 Twitter Bootstrap 创建类似 Gmail 的布局
【发布时间】:2013-03-27 18:39:07
【问题描述】:

是否可以使用 Twitter Bootstrap 创建类似 GMail/GoogleGroups 的布局,以便布局始终适合视口(窗口高度)并且侧边栏和内容区域是 可单独滚动?

--------------------------------------------------------------------------
|                                                                        |
|                    Fixed top navbar                                    |
--------------------------------------------------------------------------
|         |                                                              |   
| Sidebar |       Content area scrollable                                |
| scrollable                                                             |
|         |                                                              |
|         |                                                              |
|         |                                                              |
|         |                                                              |
|------------------------------------------------------------------------|

【问题讨论】:

标签: javascript html css twitter-bootstrap


【解决方案1】:

您不需要使用 Bootstrap 来创建此布局(我认为 Bootstrap 也不支持它,至少在没有重大修改的情况下不支持)。

当然,您仍然可以将 Bootstrap 用于页面上的所有其他内容。如果您真的想要 Google Apps 的外观,则需要调整一些默认的 Bootstrap 样式。

什么是可能的

为了好玩,这里使用我在下面描述的基本技术和各种 Bootstrap 组件快速仿制了 Gmail 界面。

演示: http://jsfiddle.net/Ly6wmyr2/1/

这里的代码绝对是演示质量,超出了堆栈溢出问题的范围。我会留给读者去剖析。

简单分解

演示: http://jsfiddle.net/vLm26g4g/1/

备注

  1. 我们使用的是绝对定位。
  2. 绝对定位并不意味着它不能响应(如果需要)。
  3. 使用 100% 高度主体内的所有 4 个侧面来定位容器。
  4. 此方法适用于所有浏览器 IE 7+。如果可以支持 IE8+,使用box-sizing: border-box 可以让维度计算更容易。
  5. 这样的布局确实受益于 LESS CSS,因为您可以在一个位置声明基本尺寸。

HTML {
    height: 100%;
}
BODY {
    position: relative;
    height: 100%;
}
HEADER {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    padding: 8px;
    background-color: #ddd;
}
#side {
    position: absolute;
    top: 80px;
    left: 0;
    bottom: 0;
    width: 20%;
    background-color: #eee;
    overflow: auto;
}
#content {
    position: absolute;
    top: 80px;
    left: 20%;
    bottom: 0;
    right: 0;
    overflow: auto;
}

【讨论】:

    【解决方案2】:

    我认为没有开箱即用的 Bootstrap 解决方案,但对 Bootstrap CSS 的覆盖很少,并且在 左侧导航周围有一个 position:absolute 容器 和 *宽内容*a 这应该可以。您会看到左右跨度都有独立的滚动条...

    Gmail-like Bootstrap Layout Demo

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container-fluid">
    
          <!-- top nav --->
    
        </div>
      </div>
    </div>
    <div class="box">
      <div class="row-fluid">
        <div class="column span3">
    
         <!-- left-side nav --->
    
        </div>
        <div class="column span9">
    
         <!-- content area --->
    
        </div>
      </div>
    </div>
    

    添加一些 Bootstrap CSS 覆盖,并调整 .box 和 .column 容器..

    html, body {
        height: 100%;
    }
    
    .row-fluid {
        height: 100%;
    }
    
    .column:before, .column:after {
        content: "";
        display: table;
    }
    
    .column:after {
        clear: both;
    }
    
    .column {
        height: 100%;
        overflow: auto;
    }
    
    .box {
        bottom: 0; /* increase for footer use */
        left: 0;
        position: absolute;
        right: 0;
        top: 40px;
    }
    
    .span9.full {
        width: 100%;
    }
    

    这里是有效的 Bootply:http://bootply.com/60116(还包括内容区域行和分页)

    【讨论】:

      【解决方案3】:

      查看脚手架部分

      http://twitter.github.com/bootstrap/scaffolding.html#layouts

      特别是在 Fluid Layout/Fixed Layout 部分下

      如果你想让这些部分可以滚动,只需添加

      overflow-y:auto;
      

      到你的 div 中的 css

      【讨论】:

      • 我试过了,但它似乎不起作用。也许是因为我正在用 javascript 动态填充部分 div?这些部分没有显示滚动条,我只是使用标准浏览器滚动条来滚动整个窗口。
      • 会的。你必须做一些 CSS 工作才能做到这一点:调整具有特定高度的 div 并在 CSS 中设置 overflow property。
      • 当我希望 div 适合窗口高度时,为什么要设置特定高度?
      【解决方案4】:

      这将是您的代码使用滚动间谍来突出显示正文中当前的“可见”部分

          <body data-spy="scroll" data-target=".bs-docs-sidebar">
      <div class="container-fluid">
        <div class="row-fluid">
          <div class="span3 bs-docs-sidebar">
              <ul class="nav nav-list bs-docs-sidenav affix">
                <li class="active"><a href="#global"><i class="icon-chevron-right"></i> Global styles</a></li>
                <li><a href="#gridSystem"><i class="icon-chevron-right"></i> Grid system</a></li>
                <li><a href="#fluidGridSystem"><i class="icon-chevron-right"></i> Fluid grid system</a></li>
                <li><a href="#layouts"><i class="icon-chevron-right"></i> Layouts</a></li>
                <li><a href="#responsive"><i class="icon-chevron-right"></i> Responsive design</a></li>
              </ul>
            </div>
          <div class="span9">
              <section id="global"></section>
              <section id="gridSystem</section>
              <section id="fluidGridSystem"></section>
              <section id="layouts"></section>
              <section id="responsive"></section>
          </div>
        </div>
      </div>
      </body>
      

      如果你想添加一个固定的导航栏,只需将“位置:固定”添加到导航栏 css

      【讨论】:

        猜你喜欢
        • 2013-09-25
        • 2017-01-26
        • 2012-09-30
        • 1970-01-01
        • 2011-08-08
        • 2013-10-15
        • 2022-01-06
        • 1970-01-01
        • 2012-02-03
        相关资源
        最近更新 更多