2012-07-23 102 views
0

假设我有一个500宽和700高的div。如何在特定高度上放置水平线或图像作为背景? 我已经张贴在这里也http://jsfiddle.net/jt74S/如何在div的指定高度添加水平线?

<div id="main"> 
these are some text and stuff, however the horizontal line/image should not be added with the text, but as a background of these. 
</div> 

#main { 
    background: none repeat scroll 0 0 rgba(56, 56, 56, 0.75); 
    border-radius: 0 3px 0 3px; 
    float: left; 
    font-size: 48px; 
    line-height: 44px; 
    padding: 20px; 
}​ 

回答

0

也许background-position CSS属性会工作。

实施例这里:

http://jsfiddle.net/rnSDw/1/

可以将背景位置属性更改为板状的左侧,中心等,或像素精确定位的关键词。

+0

请问您能举个例子吗? – EnexoOnoma 2012-07-23 02:29:38

+0

谢谢你,但我必须保持'背景:无重复滚动0 0 rgba(56,56,56,0.75);' – EnexoOnoma 2012-07-23 02:53:51

0

您可以将线条作为必需高度的一个像素宽的背景图像,然后在整个页面上重复该线条。或者你可以使#main position:relative并给它一个子div {left:0;正确:0; height:npx; border-bottom:你的规格; }。但是,希望@ joeschmidt45的建议是一个行家,你不需要做任何事情,这样就不需要太多的经验。