您的位置:首页 > Web前端 > CSS

How to include cascading style sheets (CSS) in JSF

2015-08-28 07:31 746 查看
In JSF 2.0, you can use
<h:outputStylesheet />
output a css file.

For example,

<h:outputStylesheet library="css" name="style.css"  />

It will generate following HTML output…

<link type="text/css" rel="stylesheet"
href="/JavaServerFaces/faces/javax.faces.resource/style.css?ln=css" />

JSF outputStylesheet example

An example to show the use of JSF 2
<h:outputStylesheet />
to render a “style.css” file, locate in the “
resources/css
” folder, see figure below :



JSF file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
>
<h:head></h:head>
<h:body>

<h1>JSF 2 outputStylesheet example</h1>

<h:outputStylesheet library="css" name="style.css"  />

<div class="red">This is red color</div>

</h:body>

</html>

It will generate following HTML output

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="/JavaServerFaces/faces/javax.faces.resource/style.css?ln=css" />
</head>

<body>

<h1>JSF 2 outputStylesheet example</h1>

<div class="red">This is red color</div>

</body>

</html>


Warning

When render CSS file via
<h:outputStylesheet />
tag, remember put the
<h:head />
tag as well; Otherwise the css file will not be included.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: