I have newcss.css
#formdiv {
width: 30%;
margin: 150 auto;
}
和复合组件
<?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"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form id="formdiv">
...
</h:form>
</composite:implementation>
</html>
当我尝试使用这个组件时index.xhtml
我无法观察到任何影响CSS
申请。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:lpform="http://xmlns.jcp.org/jsf/composite/mycomp"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<form>
<mycomp:comp/>
</form>
</html>
我需要我的复合组件位于中心。
您遇到的问题是复合组件本身正在为表单的 id 设置前缀。如果您使用您的h:form
直接在您的主页中,您会看到表单 id 值为formdiv
在客户端(并随后正确地获取其风格)。
但是,当您使用组合时,JSF 会为组合本身建立一个 id,因此对于您的表单,您将拥有j_idtx:formdiv
。最简单的方法是使用样式类而不是 css 选择器:
.formdivClass {
width: 30%;
margin: 150px auto;
}
<composite:implementation>
<h:form styleClass="formdivClass">
...
</h:form>
</composite:implementation>
也可以看看:
- JSF 组件 id 中生成的前缀 j_idt33 是什么? https://stackoverflow.com/questions/8279189/whats-the-generated-prefix-j-idt33-in-jsf-component-id
- 如何在 CSS 选择器中使用 JSF 生成的带有冒号“:”的 HTML 元素 ID? https://stackoverflow.com/questions/5878692/how-to-use-jsf-generated-html-element-id-in-css-selectors
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)