css 不适用于 html 组件

标签 css jsf

我不明白为什么 css 类不起作用。

newcss.css:

.greenClass {
    color: green;
}

索引.xhtml:

<?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://xmlns.jcp.org/jsf/html">
    <h:head>
        <h:outputStylesheet library="css" name="newcss.css"/>
    </h:head>
    <h:form styleClass="greenClass">
        <h:outputLabel styleClass="greenClass" value="AAA"/>
    </h:form>
</html>

HTML代码

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2"><link type="text/css" rel="stylesheet" href="/WA/faces/javax.faces.resource/newcss.css" /></head>
<form id="j_idt4" name="j_idt4" method="post" action="/WA/faces/index.xhtml" class="greenClass" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt4" value="j_idt4" />
<label class="greenClass">AAA</label><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="-7146797988252848648:-7580080555543519594" autocomplete="off" />
</form>
</html>

这行不通

<?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://xmlns.jcp.org/jsf/html">
    <h:form>
        <h:outputLabel styleClass="greenClass" value="AAA"/>
    </h:form>
</html>

但以下工作正常:

<?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://xmlns.jcp.org/jsf/html">
    <h:form>
        <h:outputLabel style="color: green" value="AAA"/>
    </h:form>
</html>

HTML代码:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<form id="j_idt2" name="j_idt2" method="post" action="/WA/faces/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt2" value="j_idt2" />
<label style="color:green">AAA</label><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="8578298320156968921:4997153480898762925" autocomplete="off" />
</form>
</html>

你能解释一下这可能是什么原因以及如何解决这个问题吗?

最佳答案

在你的例子中,这是行不通的,你错过了

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

部分。

关于css 不适用于 html 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20302306/

相关文章:

jsf - 在 ManagedProperty 中使用 ResourceBundle 中的属性

java - 如何转换 PrimeFaces p :dataTable to standard h:dataTable (without skin) and then print it

css - 如何在左侧打开 Primefaces 子菜单?

html - 位置 :fixed and margin:0 auto not working in IE

html - 图片在我的网站上损坏,但一般都能正常工作

css - 使用 CSS 绘制三 Angular 形

javascript - JSF 标签禁用注销按钮的 css 首选项

javascript - 为什么缩放浏览器时会忽略@media 查询?

html - 图像作为列表中的链接

java - jsf将数据传递到其他页面不起作用