jsf页面中样式和样式类的区别

时间:2021-11-03 20:07:17

I have started working with a java code base where style and styleClass keywords are used to style the different elements in the jsf page. The project is using jsf 2.2.

我已经开始使用一个java代码基,其中风格和styleClass关键字用于在jsf页面中对不同元素进行样式化。项目使用的是jsf 2.2。

The 'style' keyword is used to apply html attributes like:

“style”关键字用于应用html属性,如:

<h:panelGroup style="margin-top:60px">
</h:panelGroup>

where as 'styleClass' keyword is used to apply the classes/styles from the .css file like:

使用'styleClass'关键字来应用.css文件中的类/样式,如:

<h:panelGroup layout="block" styleClass="panel panel-default">    
</h:panelGroup>

So my question is, is there a rule for which keyword is used where or is it just a matter of choice in this case? From this link I don't understand any difference between the two keywords.

所以我的问题是,在什么地方使用关键字是否有规则,或者在这种情况下只是一个选择的问题?从这个链接中我看不出这两个关键字之间有什么区别。

1 个解决方案

#1


3  

Both attributes are used to define style properties for the component. The styleClass attaches css classes to the component while the style attribute is used to define inline style properties that will be applied to the single element.

这两个属性都用于为组件定义样式属性。styleClass将css类附加到组件中,而style属性用于定义将应用于单个元素的内联样式属性。

this:

这样的:

<h:panelGroup style="margin-top:60px">
</h:panelGroup>

would generate the following HTML:

将生成以下HTML:

<span style="margin-top: 60px"></span>

Note that it is a span HTML element because the panelGroup renders a span by default.

注意,它是一个span HTML元素,因为panelGroup在默认情况下呈现一个span。

while

<h:panelGroup layout="block" styleClass="panel panel-default">    
</h:panelGroup>

would generate:

会产生:

<div class="panel panel-default"></div>

This is basic HTML knowledge anyway has not much to do with JSF except for the naming (i.e. style and styleClass)

这是基本的HTML知识除了命名(即样式和样式)之外,与JSF没有太大关系

#1


3  

Both attributes are used to define style properties for the component. The styleClass attaches css classes to the component while the style attribute is used to define inline style properties that will be applied to the single element.

这两个属性都用于为组件定义样式属性。styleClass将css类附加到组件中,而style属性用于定义将应用于单个元素的内联样式属性。

this:

这样的:

<h:panelGroup style="margin-top:60px">
</h:panelGroup>

would generate the following HTML:

将生成以下HTML:

<span style="margin-top: 60px"></span>

Note that it is a span HTML element because the panelGroup renders a span by default.

注意,它是一个span HTML元素,因为panelGroup在默认情况下呈现一个span。

while

<h:panelGroup layout="block" styleClass="panel panel-default">    
</h:panelGroup>

would generate:

会产生:

<div class="panel panel-default"></div>

This is basic HTML knowledge anyway has not much to do with JSF except for the naming (i.e. style and styleClass)

这是基本的HTML知识除了命名(即样式和样式)之外,与JSF没有太大关系