如何从CSS参考嵌入图像?图像、CSS

2023-09-02 01:53:12 作者:曦.

我有一个嵌在我的组件中的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)]
 

如何用CSS往图片上嵌入文字

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")]

 
精彩推荐
图片推荐