【问题标题】:background-image: url("") in CSS h:outputStylesheet is not loading [duplicate]背景图像:CSS h:outputStylesheet中的url(“”)未加载[重复]
【发布时间】:2012-11-14 02:22:29
【问题描述】:

抱歉,如果问题没有正确提出。图像在 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 {资源添加多次}

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

不确定如何加载 css 中并应用于类的图像。

将 EDIT 图标显示为点击下一页的链接。

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

【问题讨论】:

    标签: jsf-2 resources background-image outputstylesheet


    【解决方案1】:

    您应该在 CSS 中使用 EL 变量 #{resource} 来指定图像资源。

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

    另见:

    【讨论】:

    • 谢谢。我将对其进行测试并尽快将您的答案标记为已接受。你能不能也回复一下这个问题stackoverflow.com/questions/13573178/…。对你来说很容易。
    • 对于生成自己的 css 的项目来说,这很容易,但是有几个插件和主题有自己的一堆 css,为此更改每一个外部 css 是可怕的。还有其他方法吗?我有同样的问题,但很难打开每一个 css 并更改该行
    • @maxtorzito: checkout OmniFaces UnmappedResourceHandler(或者......使用编辑器的内置查找和替换功能,Eclipse 甚至支持正则表达式)
    • @BalusC 谢谢你,我现在已经测试过了,并且可以处理 css 文件中的任何更改!!!! UnmappedResourceHandler 很棒!!非常感谢
    猜你喜欢
    • 2014-02-17
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2015-04-16
    • 2015-02-28
    • 1970-01-01
    相关资源
    最近更新 更多