【问题标题】:Is there a way in Bootstrap to "split" a column on small screens?Bootstrap 有没有办法在小屏幕上“拆分”一列?
【发布时间】:2014-09-19 09:02:40
【问题描述】:

我正在使用 Bootstrap 3。 在大屏幕上,我希望左侧有一个侧边栏,右侧有一个主要内容。在小屏幕上,我希望将侧边栏的重要块放在顶部,然后是主要内容,然后是侧边栏的不太重要的块。有没有办法做到这一点?

这是一个显示问题的 JS Bin:http://jsbin.com/wibucopi/1/ 和下面是当前代码(但是,它会在小屏幕上显示所有侧边栏内容)。

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3">
      <div class="upper" style="background:red">
        <h3>I want to be <b>above</b> the main content on small screens!</h3>
      </div>
      <div class="lower" style="background:green">
        <h3>I want to be <b>below</b> the main content on small screens!</h3>
      </div>
    </div>
    <div class="col-sm-9">
      <h1>Main content</h1>
      <p>Lorem ipsum dolor sit amet</p>
    </div>
  </div>
</div>

我已经玩过col-sm-pull/push-x,但我只能实现整个侧边栏显示在小屏幕上的主要内容下方。

我不想复制内容并用visible-XYhidden-XY 显示/隐藏它,因为页面会变得更大,而且感觉不对。

如果有一个纯 Bootstrap css 解决方案,或者至少只有一个 css 解决方案(我不想使用 js),那就太好了。

【问题讨论】:

  • 你可以定义Media queries (CSS)
  • @KyleEmmanuel 我知道。但我仍然想不出一种拆分列的方法:/

标签: css twitter-bootstrap responsive-design twitter-bootstrap-3 media-queries


【解决方案1】:

你可以这样做:

Bootply Demo

HTML:

<div class="container-fluid">
  <div class="row">
    <div class="upper col-sm-3" style="background:red">
      <h3>I want to be <b>above</b> the main content on small screens!</h3>
    </div>
    <div class="col-sm-9 col-sm-pull-right">
      <h1>Main content</h1>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
      <p>Lorem ipsum dolor sit amet</p>
    </div>    
    <div class="lower col-sm-3" style="background:green">
      <h3>I want to be <b>below</b> the main content on small screens!</h3>
    </div>
  </div>
</div>

CSS:

@media (min-width: 768px) {
  .col-sm-pull-right {
      float: right;
  }
}
.lower {
  clear: left;
}

【讨论】:

  • 谢谢!除了 maincontent 比上部(红色)侧边栏短的情况外,这很有效。在这种情况下,下部(绿色)侧边栏显示在主要内容下方。你认为也有办法解决这个问题吗?
  • 我现在根据 Michael Strelan 的反馈更新了答案。如果主要内容比侧边栏短,它现在也可以工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多