html - Bootstrap 3、容器结构的2列流体容器

标签 html css twitter-bootstrap-3

我正在尝试创建一个 container-fluid 容器,该容器具有用于背景颜色/图像需求的两列结构,其中包含一个 container 类。容器类在那里是为了让内容与非 container-fluid 类容器保持一致。与两种背景颜色的全宽列结构对齐是我的目标。

这是我正在尝试创建的可视化示例。 enter image description here

请参阅下面的代码以了解我到目前为止的尝试...

.flex { display: flex; }

.container-fluid { background: #fff; }
  .container-fluid .col-sm-6:last-of-type { background: #000; color: #fff; }

  .container-fluid .container { width: initial; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <p>This is a container class. The content below should align with this containers content.</p>
    </div>
  </div>
</div>


<div class="container-fluid">
  <div class="row flex">
  
    <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-0">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h4>Column 1</h4>
            <p>This content needs to align with the container class above.</p> 
          </div>
        </div>
      </div>
    </div>
    
    <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-0">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h4>Column 2</h4>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</div>

最佳答案

每个 row 类添加一个 -15px margin-leftmargin-right 也每个 col-* 类类添加了一个15px padding-leftpadding-right。这些需要正确匹配。我还删除了似乎会增加错位的偏移类。如果您需要相同的内容,请将其添加回来。希望此解决方案适合您。

.flex {
  display: flex;
}

.container-fluid {
  background: #fff;
}
.container-fluid .col-sm-6:last-of-type {
  background: #000;
  color: #fff;
}

.container-fluid .container {
  width: initial;
}
<link
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
  rel="stylesheet"
/>

<div class="container-fluid">
  <div class="row">
    <div class="col-xs-12">
      <p>
        This is a container class. The content below should align with this
        containers content.
      </p>
    </div>
  </div>
</div>

<div class="container-fluid">
  <div class="row flex">
    <div class="col-xs-10 col-sm-6">
      <div class="row container">
        <h4>Column 1</h4>
        <p>
          This content needs to align with the container class above.
        </p>
      </div>
    </div>

    <div class="col-xs-10 col-sm-6">
      <div class="container row">
        <h4>Column 2</h4>
      </div>
    </div>
  </div>
</div>

关于html - Bootstrap 3、容器结构的2列流体容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59545906/

相关文章:

ASP.NET Gridview 分页样式中的 C# Bootstrap 分页?

javascript - 使用 node.js 发送的样式表带有错误的 MIME 类型,我该如何解决?

javascript - 如何在连接可用时离线启动应用程序并同步

HTML5 音频 : preload attribute ignored in Chrome

c# - 使用 CSS 内联更改 HTML 以使用数据 Url

javascript - 在 Bootstrap 模态中自动播放的视频,在模态关闭时停止

javascript - 我如何将 div 放在 jquery 画廊的顶部?

javascript - 根据滚动位置播放不同的音频文件

javascript - 我的网站上传后无法正常运行

javascript - Bootstrap Switch 显示/隐藏表列 - 初始配置和值存储