background-image: url(“”) in CSS h:outputStylesheet is not loading [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:41:33

问题


Sorry if question is not properly asked. Image is showing fine in struts project but not in JSF2 project. All the css and buttons are rendering fine except image that has url in css.

Folder structure

resources -> css -> bootstrap.min.css
resources -> img -> glyphicons-halflings.png

bootstrap.min.css

background-image: url("../img/glyphicons-halflings.png");

1 - if I use <h:outputStylesheet library="css" name="bootstrap.min.css"/> than background-image url generated is http://localhost:8000/img/glyphicons-halflings.png thus image not loading. It should be http://localhost:8000/resources/img/glyphicons-halflings.png

2 - If I use <link href="#{request.contextPath}/resources/css/bootstrap.min.css" rel="styleSheet" type="text/css"/> than

Firefox -> Firebug -> Net tab {resources added multiple times}

http://localhost:8000/resources/resources/img/glyphicons-halflings.png

not sure how to load image which is in css and applied on class.

show EDIT icon as link to click to next page.

 <h:outputLink value="edit.xhtml" >
                            <i class="icon-edit" ></i>
                            <f:param name="id" value="#{person.id}"/>
                        </h:outputLink>


回答1:


You should be using the EL variable #{resource} in CSS to specify image resources.

background-image: url("#{resource['img/glyphicons-halflings.png']}");

See also:

  • How to reference JSF image resource as CSS background image url


来源:https://stackoverflow.com/questions/13567714/background-image-url-in-css-houtputstylesheet-is-not-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!