1

I have two base CSS classes:

.smpb_color_gray {
    color:#cccccc;
}

.smpb_font_size_18 {
    font-size:18pt;
}

I wonder if it's possible to create one class which will contains both these classes? With name .smpb_my_combine_class and it must have color:#cccccc and fontSize:18pt.

I want to create one class and then use them on other classes.

Like I want to create:

.smpb_base_border_width{
    border-width:1;
}

And then I want to create a class for other control, I want to just include this class, but not create a new class. It's needed if I want to change the default width in future.

If I make a change in the base, then I need that change in all classes.

1
  • 2
    Like, .smpb_my_combine_class{color:#CCC;font-size:18pt;}? Or, <div class="smpb_color_gray smpb_font_size_18"></div>? Commented Jul 3, 2013 at 11:58

6 Answers 6

2

In regards to JavaFX2, in the .root element you can define a property, such as -smpb-color-gray:#cccccc; and then reference that within another css class.

.root {
  -smpb-color-gray: #cccccc;
  -smpb-font-size: 18pt;
}

.smpb_my_combine_class {
  -fx-text-fill: -smpb-color-gray;
  -fx-font: -smpb-font-size;
}

I used -fx-text-fill because I didn't know exactly what you were trying to color.

Does that fit into your criteria?

Sign up to request clarification or add additional context in comments.

2 Comments

It's almost what i need. Can you give link where read about this? Almost because: it's like constants, but not complex.
There's not a lot of detail that I could find. Take a look at this Oracle tutorial. Specifically, the "Rules and Properties" and "Skinning the Scene" sections. Also, check out the [CSS Reference]().
1

try this

.smpb_font_size_18,.smpb_color_gray{
    color:#cccccc;
    font-size:18pt;
}

1 Comment

? it's not what i looking for.
0

You can assign multiple classes to one html element like this <div class="border black"></div> but you cannot combine multiple classes in one as far as I know.

I haven't really looked into it much, but I think SASS might be able to do what you want.

Comments

0

If you mean using it like this:

.myclass {
  .testclass;
}

than the answer is no unless you look into something like LESS.

1 Comment

Than less is what you need :)
0

It is:

.smpb_font_size_18,.smpb_color_gray{
    /*whatever style for both*/
}

Comments

0

Basically, what you are asking is what Cascading Style Sheets are all about... Grouping Elements with the same top-level Classes or Ids together. The only thing you would have to do is to create your .smpb_my_combine_class and define the values like this:

.smpb_my_combine_class{
    color:#cccccc;
    font-size:18pt;
}

And then define your sub classes to replace the top-level class value with the default value like this:

.smpb_my_combine_class .smpb_color_gray{
    font-size: medium; //The default value for font-size according to W3C
}

.smpb_my_combine_class .smpb_font_size_18{
    color: black; //The default value of your Page font color?
}

So your .smpb_my_combine_class-classed elements will have those default values, as well as each class based on it. But keep in mind that this will only work if your subclass element is contained within an element of the .smpb_my_combine_class-class

1 Comment

Your solition it's revers of what i need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.