html - 如何在 twitter bootstrap 容器内设置 100% 宽度的背景?

标签 html css wordpress twitter-bootstrap

我目前正在构建一个 wordpress 网站,我需要一个 100% 宽度的背景(css 颜色,无图像)作为 div。我的 div 在容器内,我无法修改 html。所以,我想知道是否有任何方法可以使用 css 来做到这一点。我已经尝试过 padding+margin hack,但没有用。

HTML:

<div class="container">
 <div class="row-fluid">
   <div class="main span12">
       <div class="row-fluid blue"> <!--this is the div that needs the background-->
          <div class="span4">some content</div>
           <div class="span4">some content</div>
          <div class="span4">some content</div>
          </div>
       <div class="row-fluid">
           <div class="span12"> some other content, doesn't need the background</div>
       </div>
     </div>
  </div>
  </div>

非常感谢任何帮助。我试过这个:http://www.sitepoint.com/css-extend-full-width-bars/但它没有用。

最佳答案

基于 CSS 技巧 ( Full Width Browser Bars ) 中的这篇文章。

HTML

<div class="container">
  <div class="level"></div>
  <div class="level purple"></div>
  <div class="level"></div>
</div>

CSS

html, body {
    overflow-x: hidden;
}
.container {
  width:960px;
  margin: 0  auto;
  border:1px solid black;
}
.level {
  height:100px;
  background: #bada55;
}

.purple {
  position: relative;
  background: #663399;
}

.purple:before, 
.purple:after {
  content: "";
  position: absolute;
  background: #663399;  /* Match the background */
  top: 0;
  bottom: 0;
  width: 9999px;   /* some huge width */
} 
.purple:before {
  right: 100%; 
}
.purple:after {
  left: 100%;
}

Codepen Demo

应支持 IE8 及更高版本

关于html - 如何在 twitter bootstrap 容器内设置 100% 宽度的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24344261/

相关文章:

html - 更改图像映射的颜色

javascript - 如何在 popup.html 中执行 JavaScript

css - 以编程方式操作 CSS 文件

jquery - 使用 jquery 的背景定位在 IE7 中不起作用

php - WooCommerce - 为免费用户计划添加运费

javascript - Document 和 Element 是什么关系?为什么父元素也有 getElementsByTagName 方法?

html - 图像在打印预览中调整大小

wordpress - 将 lightsail 实例从子域移动到子文件夹

CSS 问题 : Why is sidebar not clickable?

javascript - 如何设置不同的打印介质