0

How to use different styles for the same component in a window?

asked 2009-03-03 16:54:39 +0800

etamas gravatar image etamas
78 2

I would like to insert two tabboxes in a window with two different styles. If I use a css-file for the style-definitions for tabbox1 and another css-file for tabbox2 then the second css-definitions are used for both tabboxes. How can I achieve what I want, please help me.


My problem in deeper detail:

I have a window with two tabboxes in it. For both tabboxes I want to use the default css definitions but make a few changes. That´s why I have a css-file "tabbox1.css" that I want to use for the first tabbox and I have a css-file "tabbox2.css" that I want to use for the other tabbox.

I use two java classes for the tabboxes (cTabboxOne.java and cTabboxTwo.java) which I include in the zul-file as follows:

<window>
<tabbox use="cTabboxOne">
...
</tabbox>
<tabbox use="cTabboxTwo">
...
</tabbox>
</window>

the java classes (cTabboxOne.java and cTabboxTwo.java) extend Tabbox and only have a onCreate() method:

(cTabboxOne.java)
public void onCreate() {
Style s = new Style("tabbox1.css");
s.setParent(this.getParent());

setStyle(s.getContent());
}

(cTabboxTwo.java)
public void onCreate() {
Style s = new Style("tabbox2.css");
s.setParent(this.getParent());

setStyle(s.getContent());
}


The tabboxes should use every change from the css-file. The problem is, that the css-file for the second (last) tabbox overrides the css-file for the first tabbox. That´s why both tabboxes look alike (both have the css-definitions of the second tabbox). Is there a possibility to use two different tabboxes like the way I described it (with css-files)?

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2009-03-03 20:48:01 +0800

sreed gravatar image sreed
195 1 3 5

I think you can use CSS classes to define the two styles and then specify the tabboxes with their classes:

<window>
<tabbox use="cTabboxOne" style="tabbox1">
...
</tabbox>
<tabbox use="cTabboxTwo" style="tabbox2">
...
</tabbox>
</window>

------------------
css file:

.tabbox1 { ... }
.tabbox2 { ... }

link publish delete flag offensive edit

answered 2009-03-03 20:53:18 +0800

etamas gravatar image etamas
78 2

I will try it this way but isn´t there a possibility to use the whole css-file? There are more classes that I want to use at the same time and style="tabbox1 tabbox2 ... tabboxn" doesn´t seem an elegant way to solve my problem!?

link publish delete flag offensive edit

answered 2009-03-03 21:03:38 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-03 21:04:18 +0800

If there are multiple components that can share a style they can all use the same class. Then you wouldn't name them tabbox1, etc, but use a name that makes sense for each class. My names were just examples. CSS supports a class hierarchy and inheritance that you could exploit.

link publish delete flag offensive edit

answered 2009-03-03 21:17:06 +0800

etamas gravatar image etamas
78 2

There still remain some problems...

I have 2 css-files: tabbox1.css with all the definitions for tabbox1 and tabbox2.css with all the definitions for tabbox2. The problem is that I cannot name the css-classes myself because I want to overwrite the default css-classes. So the names of the css-classes are 1) given and 2) the same in both css-files.

tabbox1.css contains:
.z-tab-ver-body {
background-color:#99ccff;
background-image:none;
}
.z-tab-ver-body em {
background-color:#99ccff;
background-image:none;
padding-bottom:10px;
}

tabbox2.css contains:
.z-tab-ver-body {
background-color:#66ffcc;
background-image:none;
}
.z-tab-ver-body em {
background-color:#66ffcc;
background-image:none;
padding-bottom:10px;
}

To reference the css-files I have to include the following lines in the zul file:
<style src="tabbox1.css"/>
<style src="tabbox2.css"/>
Now all the definitions of tabbox1.css are overwritten by the definitions of tabbox2.css (because all the names of the css-classes are equivalent)
That´s why I have to ask again, if there is a possibility to overwrite the default css-definitions for one component two times in a window.

Thanks for your help, I really appreciate it!

link publish delete flag offensive edit

answered 2009-03-03 22:10:24 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-03 22:10:57 +0800

I am not a CSS expert and realize that in my ignorance I have misled you a bit. Please have a look at this web page http://dorward.me.uk/www/css/inheritance/#oo-style. It explains that CSS does not support a class hierarchy (as I incorrectly stated previously!) but provides other approaches to achieve similar results. I think you will find the techniques described there (especially the multiple classes approach) will allow you obtain the results you want with a single merged CSS file.

link publish delete flag offensive edit

answered 2009-03-05 00:51:45 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-05 00:53:04 +0800

The following link will help even more I think: http://www.w3.org/TR/CSS21/selector.html#class-html. It explains how to use classes to specialize styles for different versions of the same component:

.z-tab-ver-body.class1 {
background-color:#99ccff;
background-image:none;
}
.z-tab-ver-body.class2 {
background-color:#66ffcc;
background-image:none;
}

---------------
<tabbox id="tabbox1" class="class1">...</tabbox>
<tabbox id="tabbox2" class="class2">...</tabbox>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-03-03 16:54:39 +0800

Seen: 185 times

Last updated: Mar 05 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More