如何从CSS参考嵌入图像? [英] How to reference embedded images from CSS?

查看:138
本文介绍了如何从CSS参考嵌入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌在我的组件中的CSS文件。我需要设置的背景图像使用此CSS文件的某些内容,并且图像需要是嵌入的资源也。这可能吗?有没有什么办法可以可靠地做到这一点?

我把现有的样式表到这个DLL,然后实现图像显示不出来的时候碰到了这个问题。我不知道有什么办法让它工作,但因为我需要知道的URL嵌入图像。

有没有人做过这样的事?

解决方案

 <%= WebResource(image1.jpg)%>
 

您可以使用上面的语句你的CSS文件中,虽然你注册你的CSS WebResourceAttribute,您可以设置PerformSubstitution为真。

  Default.css
体{
    背景:<%= WebResource(xyz.jpg)%>
}



[组装,WebResource(Default.css,文本/ CSS,PerformSubstitution =真)
[组装,WebResource(xyz.jpg,图像/ JPG)]
 

I have a CSS file that is embedded in my assembly. I need to set a background image for certain elements using this CSS file, and the image needs to be an embedded resource also. Is this possible? Is there any way I can reliably do this?

I ran into the problem when putting an existing stylesheet into this dll then realized images weren't showing up. I don't know of any way to make it work though because I would need to know the URL to the embedded image.

Has anyone done anything like this?

解决方案

<% = WebResource("image1.jpg") %>

You can use above statement inside your CSS file, and while you register your CSS with WebResourceAttribute, you can set "PerformSubstitution" to true

Default.css
body{
    background: <%=WebResource("xyz.jpg")%>
}



[assembly, WebResource("Default.css","text/css", PerformSubstitution=true)]
[assembly, WebResource("xyz.jpg","image/jpg")]

这篇关于如何从CSS参考嵌入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆