【问题标题】:How to create a column whose background stretches to the far left of the screen, but not the content?如何创建一个背景延伸到屏幕最左侧的列,而不是内容?
【发布时间】:2015-10-09 02:16:20
【问题描述】:

我花了很多时间试图弄清楚如何创建类似于 to this 的布局,其中页面内容受容器元素宽度的限制,但左侧列的背景延伸到用户屏幕的最左侧(示例中的黄色)。

我正在尝试使用 Bootstrap 执行此操作,但这似乎是不可能的,因为容器元素包含页面的内容以及它的背景。

这是我目前所拥有的JSFiddle。

该结构的一些示例代码:

<div class="row">
    <div class="container">
        <div class="col-xs-6 left-one">
            This one's background needs to stretch to the far left, on large screens.
        </div>
        <div class="col-xs-6 right-one">
            This one's background can be that of the body
        </div>
    </div>
</div>

<div class="some-content">
    <div class="container">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos minima laudantium, id a, porro aliquid expedita. Iste beatae provident architecto dolorum aspernatur maiores, ratione deserunt nesciunt magni unde repudiandae eaque.
    </div>
</div>

如果有人能为我解开这个谜团,我将不胜感激。

完整代码如下:

@import url('http://getbootstrap.com/dist/css/bootstrap.css');

body{
    background: #eee;
}

.left-one{
    background: yellow;
    height: 500px;
    padding-top: 20px;
}

.right-one{
    background: #eee;
    height: 500px;
    padding-top: 20px;
}

.some-content{
    background: lightslategray;
    padding: 20px 0;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="row">
    <div class="container">
        <div class="col-xs-6 left-one">
            This one's background needs to stretch to the far left, on large screens.
        </div>
        <div class="col-xs-6 right-one">
            This one's background can be that of the body
        </div>
    </div>
</div>

<div class="some-content">
    <div class="container">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos minima laudantium, id a, porro aliquid expedita. Iste beatae provident architecto dolorum aspernatur maiores, ratione deserunt nesciunt magni unde repudiandae eaque.
    </div>
</div>

【问题讨论】:

  • 该网站使用因纽特人 CSS,所以只需使用因纽特人及其标记作为起点

标签: css twitter-bootstrap layout twitter-bootstrap-3


【解决方案1】:

只做那个人在示例中所做的事情并使用 before 元素。

DEMO

CSS:

.left-one:before{
    background: yellow;
    bottom: 0;
    content: "";
    position: absolute;
    right: 100%;
    top: 0;
    width: 9999px;
}

【讨论】:

  • 非常感谢。忘记了伪元素有多强大,在检查网站时忽略了之前的元素。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 2017-05-21
  • 2020-04-18
  • 1970-01-01
  • 2020-04-02
相关资源
最近更新 更多