【问题标题】:Bootstrap full-width with 2 different backgrounds (and 2 columns)具有 2 个不同背景(和 2 列)的 Bootstrap 全角
【发布时间】:2019-07-30 12:07:06
【问题描述】:

这有点难以解释,这就是为什么我在谷歌上也找不到答案。

我正在使用 Bootstrap 3,我需要一个全宽背景图像。在这 2 个透明颜色背景之上。我制作了一个示例图像以使一切清楚:

1+2:组合透明色背景

3+4:组合透明色背景

1+2+3+4:组合背景图(最低层)

有谁知道这是否可行以及如何实现?感谢您的帮助!

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    是的,使用question 中概述的技术,但将其扩展到列。

    Codepen Demo(下)显示的结果比 Stack Snippet 更好,包含在其中以供参考。

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      overflow: hidden;
      /* prevent scrollbar */
    }
    .container {
      width:50%;
      margin:auto;
      margin-top: 1em;
      
      position: relative;
      overflow: visible;
    }
    .extra:before {
      content: '';
      display: block;
      /* override bootstrap */
      position: absolute;
      top: 0;
      left: 50%;
      width: 100vw;
      height: 100%;
      transform: translate(-50%, 0);
    }
    [class*="col"] {
      border: 2px solid grey;
      min-height: 120px;
      position: relative;
    }
    .left:before {
      content: '';
      position: absolute;
      height: 100%;
      width: 100vw;
      top: 0;
      right: 0;
      background: rgba(255, 0, 0, 0.5)
    }
    .right:before {
      content: '';
      position: absolute;
      height: 100%;
      width: 100vw;
      top: 0;
      left: 0;
      background: rgba(0, 0, 255, 0.25);
    }
    <div class="container extra">
      <div class="row">
        <div class="col-sm-4 left"></div>
        <div class="col-sm-8 right"></div>
      </div>
    </div>

    Codepen Demo

    【讨论】:

      【解决方案2】:

      我想我明白了.. 感谢 Paulie_D

      非常简单的例子:

      HTML:

      <div class="fullwidth">
      <div class="cell red20">xxx</div>
      <div class="container cell">
            <div class="row">
            <div class="col-sm-4 red20">xx</div>
            <div class="col-sm-8 red50">xx</div>
            </div>
        </div>
          <div class="cell red50">xxx</div>
      </div>
      

      CSS:

      .fullwidth {
        background: url('http://www.ustudy.eu/nl/wp-content/uploads/2013/10/Test-taking-from-Flickr.jpg');
          display:table;
          width:100%;
      }
      .cell{
          display:table-cell;
          vertical-align:top;
      }
      
      .red20{
          background-color:rgba(255,0,0,0.2);
      }
      
      .red50{
          background-color:rgba(255,0,0,0.5);
      }
      

      jsfiddle 链接:https://jsfiddle.net/DTcHh/14045/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-23
        • 2016-11-29
        • 2016-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多