我在 Visual Studio 解决方案的 Web 元素中有以下图像路径的代码
Folder1\Images\banner.png'
<div id="placeholder">
</div>
为此设置背景的css是
#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 的背景图像。无论我使用哪个属性,我都不会在背景中获得任何图像。 请帮忙。
最佳答案
您需要为背景图像添加一个宽度
和一个高度
以使其正确显示。
所以你想要类似的东西
#placeholder {
background-image:url('../folder1/Images/banner.png');
height: 100px;
width: 100px;
}
关于css - 在 asp.net webforms 中设置 div 的背景或背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26037742/