[英]Making a div content to “bleed” on the bottom (or prevent the background image to render)
Okey,所以基本上我有:
<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_bottom.png
圖像替換僅底部的#content
背景圖像。 #content
的負邊距幾乎可以工作,但是由於兩個圖像都是透明圖像,因此它們會重疊,因此不應該發生。
我認為我需要使#content
不要在其底部的最后200 #content
處渲染其背景。 知道我該怎么做嗎?
如果您稍微更改了標記並使用了javascript,則可以使用絕對定位的div(僅包含背景)來完成此操作。 然后加載,將#repeating-background的高度設置為(#content的高度-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);
});
創建一個嵌套在#content中的第三個div,高度為200px。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.