如何发生的背景图像到div与填充

问题描述:

顶在HTML中我有这个代码如何发生的背景图像到div与填充

<div class="page"> 
     <div id="header"> 
      ... 
     </div> 
</div> 

这里是我的CSS

.page { 
    width: 1028px; 
    background-color:#103250; 
    margin-left: auto; 
    margin-right: auto; 
} 

#header 
{ 
    background:url('/Img/SubpageBox1.png') no-repeat top; 
    height:150px; 
    padding-top:50px; 
} 

但现在我的背景图像被放置out of div ...在页面的顶部...我如何将它放在标题的顶部?

您可以指定背景图像的位置:

background:url('/Img/SubpageBox1.png') no-repeat center 50px; 

或使用background-position CSS属性。

+0

这是最干净的方式吗? –

+1

使用纯CSS - 是的:)。如果我理解正确:您需要将您的bg图像移动到50px,而不是顶部,对吗? – Samich

+0

是的,你是对的... –