CSS 需要 div 来扩展它的容器宽度

标签 css html width position absolute

这是我当前的 HTML 结构。页脚 div 单独位于 BODY 中。

  <div id="footer">
     <div class="container">
        <div id="footer-bg">
           <div class="footer1">
              <p class="p1">asd</p>
              <p class="p2">asd</p>
           </div>

           <div class="footer2">
              <p class="p1">asd</p>
              <p class="p2">asd</p>
              <p class="p3">asd</p>
           </div>

           <div class="footer3">
              <p class="p1">asd</p>
           </div>
        </div>
     </div>
  </div>

这是它的 CSS:

  #footer
  {
     position: relative;
     background: url('../footer-bg-repeat.jpg') repeat-x;
     height: 307px;
  }

  #footer #footer-bg
  {
     background: url('../footer.jpg') no-repeat top left;
     height: 528px;
     width: 1587px;
     position: absolute;
     left: -380px;
     top: -221px;
  }

  #footer .footer1
  {
     position: absolute;
     top: 137px;
  }

  #footer .footer1 .p1
  {
     position: absolute;
     left: 500px;
     background: #dcdcdc;
     height: 23px;
     width: 80px;
     text-align: center;
     line-height: 25px;
     font-weight: bold;
  }

  #footer .footer1 .p2
  {
     position: absolute;
     left: 1000px;
     top: -20px;
     background: url() no-repeat top right;
     height: 40px;
     width: 249px;
     text-indent: -9999px;
     z-index: 6;
  }

  #footer .footer2
  {
     position: absolute;
     top: 159px;
     height: 23px;
     width: 100%;
     background: #000;
  }

  #footer .footer2 p
  {
     display: inline;
     line-height: 25px;
     color: #636466;
     height: 23px;
  }

  #footer .footer2 .p1
  {
    position: absolute;
    left: 500px;
    background: url() no-repeat center right;
    width: 175px;
  }

  #footer .footer2 .p2
  {
     position: absolute;
     left: 700px;
     background: #dcdcdc url() no-repeat 60px 8px;
     width: 75px;
     padding-left: 15px;
  }

  #footer .footer2 .p3
  {
     position: absolute;
     left: 800px;
  }

  #footer .footer3
  {
     position: absolute;
     top: 190px;
  }

  #footer .footer3 .p1
  {
     position: absolute;
     left: 500px;
     width: 1000px;
  }

我正在尝试让 .footer2 和 .footer3 扩展容器的宽度,从而允许我为屏幕可能的宽度设置背景颜色。

设置 100% 宽度只是让它达到容器的大小——如我所料。但是,我怎样才能让它达到页面的宽度?

最佳答案

尝试将 left 和 right 属性都设置为 0;

关于CSS 需要 div 来扩展它的容器宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713759/

相关文章:

html - 使多个可变高度的 div 内联,但保持固定宽度的容器

html - asp.net 如何创建悬停下拉菜单导航栏

Javascript 幻灯片滑动

Javascript 如果有类,警报 "yes",否则警报 "no"

javascript - 如何在计数器结束时使用 jquery 将一个页面重定向到另一个页面?

css - 使用 BootStrap 对齐标签和值,例如标签和输入

html - 如何修复带数字的双向文本?

jquery - 使内部div比外部div宽

css - 使用CSS时 Canvas 会拉伸(stretch),但具有“width”/“height”属性的普通 Canvas

css - 是否可以使表格的前两列与其内容一样宽,而第三列占据剩余空间?