css - 如何将伪背景颜色扩展到中心容器之外而不是屏幕宽度?

标签 css twitter-bootstrap responsive-design

大家好,我需要你的帮助,我正在尝试这种交替的图像和文本设计:

enter image description here

我在 Bootstrap 中对此进行编码,这是我的代码:

<div class="container">
    <div class="row">
        <div class="col-2"><img src="images/image.png" class="img1 img-responsive"></div>
        <div class="col-10"><h4 class="details blue right">Lorem Ipsum text here...</h4></div>
    </div>
    <div class="row">
        <div class="col-10"><h4 class="details green left">Lorem Ipsum text here...</h4></div>
        <div class="col-2"><img src="images/image.png" class="img2 img-responsive"></div>
    </div>
    <div class="row">
        <div class="col-2"><img src="images/image.png" class="img3 img-responsive"></div>
        <div class="col-10"><h4 class="details orange right">Lorem Ipsum text here...</h4></div>
    </div>
</div>

和我的 CSS:

.container{
    max-width:960px;
}

.details.left:before{
content:"";
position:absolute;
height:100%;
background:inherit;
width:100%;
top:0;
left:0;
z-index:0;
overflow:hidden;
border-top-right-radius:4px;
border-bottom-right-radius:4px;
}

我的问题是文本背景的宽度超出了屏幕宽度,它创建了一个水平滚动条,我该如何裁剪背景才不会有滚动条?我只希望背景与中心容器重叠而不是屏幕宽度。

最佳答案

My problem is the width of the text background is overflowing the screen width and it creates a horizontal scroll, how do i clip the background so i won't have the scroll?

将您的容器包裹在外层包装器中并给它 overflow: hidden 并给您的 html 和 body 一个零边距

HTML

<div class="wrapper">
  <div class="container">
  ....
  </div>
</div>

CSS

html, body {
  margin: 0;
}

.wrapper {
  overflow: hidden;
}

我将此应用于您的 fiddle demo here , 虽然它看起来离你发布的屏幕转储很远

关于css - 如何将伪背景颜色扩展到中心容器之外而不是屏幕宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42454866/

相关文章:

html - 如何使选择选项文本转到 firefox 中的下一行?

css - 设置引导网格系统时出现问题

html - 你可以将一个div的信息设置为另一个div的背景图像吗?

javascript - 如何动态更新弹出内容 AngularJS Bootstrap

javascript - 重叠图像在 Bootstrap 轮播淡入淡出时缓慢交叉淡入淡出

javascript - Angular Bootstrap 中的响应式菜单

html - CSS 响应式 3 列表

css新闻文章布局问题

html - 将对象放在响应页面中的其他对象下面

javascript - 日期时间选择器显示在上方时不工作