这个问题在这里已经有了答案:
How to reference JSF image resource as CSS background image url
(2 个回答)
5年前关闭。
抱歉,如果问题没有正确提出。图像在 struts 项目中显示良好,但在 JSF2 项目中显示不正常。所有的 css 和按钮都呈现良好 except image that has url in css
.
文件夹结构
resources -> css -> bootstrap.min.css
resources -> img -> glyphicons-halflings.png
bootstrap.min.css
background-image: url("../img/glyphicons-halflings.png");
1 -
如果我使用
<h:outputStylesheet library="css" name="bootstrap.min.css"/>
生成的背景图片网址是 http://localhost:8000/img/glyphicons-halflings.png
因此图像未加载。应该是 http://localhost:8000/resources/img/glyphicons-halflings.png
2 - 如果我使用
<link href="#{request.contextPath}/resources/css/bootstrap.min.css" rel="styleSheet" type="text/css"/>
比Firefox -> Firebug -> Net tab {resources added multiple times}
http://localhost:8000/resources/resources/img/glyphicons-halflings.png
不知道如何加载 css 中的图像并应用于类。
将编辑图标显示为单击下一页的链接。
<h:outputLink value="edit.xhtml" >
<i class="icon-edit" ></i>
<f:param name="id" value="#{person.id}"/>
</h:outputLink>
最佳答案
您应该使用 EL 变量 #{resource}
在 CSS 中指定图像资源。
background-image: url("#{resource['img/glyphicons-halflings.png']}");
也可以看看:
关于jsf-2 - background-image: url ("") 在 CSS h:outputStylesheet 没有加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13567714/