如何在 ASP.NET 中设置图片作为背景?
我无法在我的页面中显示背景图片。我正在尝试使用 CSS 在母版页中执行此操作。
我有一个 CSS,其中包含以下内容:
body {
background-image: url(../images/background.jpg) no-repeat;
background-attachment: fixed;
margin-top: 0px;
}
我知道 CSS 正在被读取,因为其中定义的所有其他样式都在 .aspx 页面上工作......当然除了背景图像,背景仍然是白色的。 (顺便说一句,这在 .php 页面中工作得很好。)
我一直在网上疯狂搜索,我找到的所有答案都说上面的 CSS 代码就是答案......但它不起作用!
我正在使用以下内容:
Microsoft Visual Studio 2008 版本 9.0.30729.1 SP
Microsoft .NET Framework 版本 3.5 SP 1
火狐浏览器版本3.6.6
如果有人知道如何让它工作,请告诉我!
I am unable to get the background picture to show in my pages. I am trying to do this in the master page using CSS.
I have a CSS which contains the following:
body {
background-image: url(../images/background.jpg) no-repeat;
background-attachment: fixed;
margin-top: 0px;
}
I know the CSS is being read because all other styles defined in it are working on the .aspx pages... except of course the background image, the background remains white. (This works perfectly fine in .php pages by the way.)
I have been searching online like crazy and all the answers I find, say the above CSS code is the answer... but it is not working!
I am using the following:
Microsoft Visual Studio 2008 Version 9.0.30729.1 SP
Microsoft .NET Framework Version 3.5 SP 1
Firefox Version 3.6.6
If anybody knows how to get this to work, PLEASE let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢怀亚特·巴尼特(Wyatt Barnett),我能够弄清楚这一点。我用firebug编辑CSS文件,发现了问题。
我的路径错误,我将其从../images/background.jpg更改为--> ./images/background.jpg
属性标签错误,我从background-image改了 --> background
我不知道为什么我一开始就没有想到用 Firebug 来做到这一点(这毕竟是我拥有它的原因)所以谢谢 Wyatt 的众所周知的一巴掌 - 我需要它! :o)
Thanks to Wyatt Barnett I was able to figure it out. I used firebug to edit the CSS file and discovered the problem.
My path was wrong, I changed it from ../images/background.jpg --> ./images/background.jpg
The attribute tag was wrong, I changed it from background-image --> background
I don't know why I did not think to do this with firebug to start with (it is after all why I have it) so thank you Wyatt for the proverbial slap upside the head - I needed it! :o)
CSS 背景图像技术是正确的。但是您是否查看过 Http 调试器中的内容(例如 firebug 或 fiddler 中的网络监视器)并弄清楚您的相对路径是否没有搞砸众所周知的事情。或者,CSS 路径与 ASP.NET 和 MasterPages 有时不太一致,您可能会遇到从错误的 url 请求图像的问题,因此它不会显示。
The CSS background image technique is correct. But have you looked at things in a Http debugger (such as the net monitor in firebug or fiddler) and figured out if your relative pathing isn't screwing the proverbial pooch. Or, CSS paths and ASP.NET and MasterPages sometimes don't quite agree, you probably have an issue of requesting the image from the wrong url so it isn't showing up.