设置背景或背景图片
问题描述:
我有在Visual Studio解决方案设置背景或背景图片
Folder1\Images\banner.png'
<div id="placeholder">
</div>
和CSS的web项目后续的成像路径将下面的代码来设置此背景是
#placeholder {
position:relative;
width: 40em;
margin:auto;
height:4em;
margin-top: -1em;
padding-top: 2em;
background-image:url('../folder1/Images/banner.png');
/* background('('../folder1/Images/banner.png') */
background-size: 40em;
background-repeat:no-repeat;
clear: right;
}
我也尝试用〜而不是../符号,但它不工作。
我应该使用background-image或background属性来设置div的背景图片。无论我使用哪个属性,我都不会在后台获取任何图像。 请帮忙。
答
您需要添加一个width
和height
的背景图像才能正确显示。
所以,你要像
#placeholder {
background-image:url('../folder1/Images/banner.png');
height: 100px;
width: 100px;
}
对不起,我只是专注于背景属性。其余的属性现在已经包含在内 – Sike12 2014-09-25 13:06:36
在我的本地机器上工作得很好 – Izzy 2014-09-25 13:47:47
嗨Izzy这是关于CSS占位符的默认位置。它现在工作正常。谢谢 – Sike12 2014-09-25 14:08:21