代码之家  ›  专栏  ›  技术社区  ›  Nicolas Viennot

使div内容在底部“出血”(或阻止背景图像渲染)

  •  0
  • Nicolas Viennot  · 技术社区  · 15 年前

    好吧,基本上我有:

    <div id="content">
      ... content of arbitrary size ...
    </div>
    <div id="content_bottom"></div>
    

    风格是:

    #content {
        background: transparent url(content_tile.png) center top repeat-y;
        width: 800px;
    }
    #content_bottom {
        background: transparent url(content_bottom.png) center top no-repeat;
        height: 200px;
        width: 800px;
    }
    

    content_tile.png 是一个 800x1 图像(垂直平铺),并具有透明度。 content_bottom.png 800x200 形象。

    基本上,我需要 要替换的图像 #content 背景图片只在底部。 #内容 几乎可以工作,但由于这两个图像都是透明的图像,它们重叠,不应该发生。

    我想我需要 不是在它底部的最后200px上渲染它的背景。 知道我怎么做吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Pat    15 年前

    如果您稍微修改了标记并使用javascript,那么您可以使用一个绝对定位的div来完成它,该div只包含背景。然后加载,将“重复背景高度”设置为(内容高度-200px):

    HTML格式

    <div id="content">
        <div id="text">
             This is where your content would go
        </div>      
        <div id="repeating-background"></div>
    </div>
    

    CSS

    #content {
       position: relative;
       width: 800px;
       background: url(content_bottom.png) left bottom no-repeat;
    }
    
    #text {
       position: relative;
       z-index: 2;
    }
    
    #repeating-background {
       position: absolute;
       z-index: 1;       
       top: 0;
       left: 0;       
    
       width: 800px;
       height: 1px;
    
       background: url(content_tile.png) left top repeat-y;
    }
    

    Javascript(jQuery)

    $(document).ready(function() {
        $('#repeating-background').height($('#content').height() - 200);
    });
    
        2
  •  -1
  •   NimChimpsky    15 年前

    创建第三个div,嵌套在#content中,高度为200px。