简体   繁体   English

使用JSF和PrimeFaces覆盖/实现CSS

[英]Override/implement CSS with JSF and PrimeFaces

I use JSF and PrimeFaces and I try to modify render by changing or adding some CSS lines. 我使用JSF和PrimeFaces,我尝试通过更改或添加一些CSS行来修改渲染。

I added my CSS file named "styles.css" to my .xhtml page and it's loaded after those of PrimeFaces so I can override default values. 我将名为“styles.css”的CSS文件添加到我的.xhtml页面,并在PrimeFaces之后加载,因此我可以覆盖默认值。

PrimeFaces create a div in my page : PrimeFaces在我的页面中创建一个div:

<div id="j_idt13:universe" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all ui-helper-clearfix" style="width: 86px;">
....
</div>

I'm trying to change 86px size to 100% so in my styles.css I added : 我正在尝试将86px大小更改为100%所以在我的styles.css中我添加了:

#j_idt13:universe{
    width: 100%;    
}

but it doesn't work...With Firebug when I inspect source code, my #j_idt13:universe doesn't appear anywhere... 但它不起作用...当我检查源代码时使用Firebug,我的#j_idt13:universe不会出现在任何地方......

I can change some CSS by accessing class selector(.class) but not with id selector (#id). 我可以通过访问类选择器(.class)而不是id选择器(#id)来更改一些CSS。

In my case, how can I change 86px to 100% please ? 在我的情况下,如何将86px更改为100%?

Thanks 谢谢

Olivier 奥利维尔

The colon : is a special character in CSS selectors representing the start of a pseudo selector. 冒号:CSS选择器中的一个特殊字符,表示伪选择器的开头。 If you want to represent the colon literally as part of the element ID or class name, then you have to escape it using \\ . 如果要将冒号字面表示为元素ID或类名的一部分,则必须使用\\来转义它。

#j_idt13\:universe {

}

Note that this doesn't work in IE6/7. 请注意,这在IE6 / 7中不起作用。 You'd need to use \\3A instead (with a trailing space). 您需要使用\\3A (带尾随空格)。

#j_idt13\3A universe {

}

Also note that this will fail when you add another JSF component to the view, because j_idt13 is an autogenerated ID depending on the component's position in the view, not a fixed ID. 另请注意,当您向视图添加另一个JSF组件时,这将失败,因为j_idt13是一个自动生成的ID,具体取决于组件在视图中的位置,而不是固定ID。 Rather give the parent UINamingContainer component a fixed ID, or better, give the target component a style class, so that you can just use the class selector. 而是给父UINamingContainer组件一个固定的ID,或者更好,给目标组件一个样式类,这样你就可以使用类选择器。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM