将外部CSS文件添加到jsf的语法是什么?
试过两种方式.没有帮助.
1.
<head>
<style type="text/css">
@import url("/styles/decoration.css");
</style>
</head>
Run Code Online (Sandbox Code Playgroud)
2.
<head>
<link rel="stylesheet" type="text/css" href="/styles/decoration.css" />
</head>
Run Code Online (Sandbox Code Playgroud)
小智 11
我猜BalusC可能有你的答案.
但是,我想补充一些额外的观点:
假设您正在运行Web应用程序的子目录中.根据我的经验,您可能想尝试这个:
<link href="${facesContext.externalContext.requestContextPath}/css/style.css" rel="stylesheet" type="text/css"/>
该'${facesContext.externalContext.requestContextPath}/'链接将帮助您立即返回上下文的根目录.
编辑:删除开始/从'href="/${facesContext.ex...'.如果应用程序在根上下文中运行,则CSS URL开始,//并且浏览器无法找到CSS,因为它被解释为http://css/style.css.
我从来没有使用过第一个,但第二个在语法上是有效的,应该在技术上有效.如果它不起作用,那么href属性中的相对URL 就是错误的.
在相对URL中,前导斜杠/指向域根.因此,如果JSF页面是例如请求的http://example.com/context/page.jsf,那么CSS URL将绝对指向http://example.com/styles/decoration.css.要知道有效的相对URL,您需要知道JSF页面和CSS文件的绝对URL,并从另一个中提取一个.
假设您的CSS文件实际位于http://example.com/context/styles/decoration.css,那么您需要删除前导斜杠,使其相对于当前上下文(其中一个page.jsp):
<link rel="stylesheet" type="text/css" href="styles/decoration.css" />
Run Code Online (Sandbox Code Playgroud)
更新的JSF 2.0方法有点整洁.代替:
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/compass.css"/>
Run Code Online (Sandbox Code Playgroud)
你现在这样做:
<h:outputStylesheet library="css" name="compass.css"/>
Run Code Online (Sandbox Code Playgroud)
并且样式表资源应放在resources\css.Where资源与WEB-INF处于同一级别的位置.
| 归档时间: |
|
| 查看次数: |
37280 次 |
| 最近记录: |