[ACCEPTED]-copy css from one class to another?-stylesheet

Accepted answer
Score: 10

You can use:

<div class="element1 element2">

while having

.element1{
  font-size:14px;
}

.element2{
  font-weight:bold;
}

and so both classes 4 will apply. jQuery is smart enough to add 3 classes and remove classes like this.

Also 2 you can use something more advanced like 1 SASS that alows mixins.

Score: 1

As far as I'm aware, no, this isn't possible 8 with CSS alone. You've already identified 7 one way of achieving your aims, and I'd 6 have to suggest that it's the better way.

In 5 CSS a class can only inherit from its parent, and 4 then only if <example-attribute>: inherit; (I've used this with color:, background-color:, font-family:, font-size: among 3 others, though I warn you that if the font-size of 2 the parent a size described as an increase 1 or decrease, the font-size will change in the child, too.

Score: 1

CSS really needs this functionality. Specifying 22 multiple classes at the element level is 21 great, but not the same as being able to 20 go:

.my_class { class:my_global_class; }

Being able to have a class use styles 19 from another class, would be very powerfull. It 18 would move this part of the inheritance 17 model into the CSS where it belongs, leaving 16 less cluttered markup.

I'm working on a site 15 right now, where we have lots of different 14 combinations of fonts. Some h and p tags 13 look different depending on their page and 12 context. It's a real pain having to have 11 our list of fonts for font-family having 10 to exist in every class where we need them. I'd 9 love to be able to do this:

/* defualt for p tags */
p { font-family:Times, Arial, Helvetica; }

/* exceptions */
.arial {font-family:Arial, Times, Helvetica; }
.segoe {font-family:Segoe, Arial, Helvetica; }

.my-page1 p {class:arial;}
.my-page2 p {class:segoe;}

In the above, my 8 list of fonts would exist in one central 7 place and I can apply them where ever I 6 want, purely in the CSS file. If I have 5 100 p tags in my site, then I have to add 4 a "class" to each of them for those exceptions, which 3 can be a pain. This is especially true, when 2 you have multiple developers working on 1 one site.

Score: 0

From what you describe you want .element1 16 to be available and used on several pages, but 15 on a few exceptional pages you want elements 14 implementing the .element1 class to look 13 different, in your example bold.

The answer 12 you were given is definitely one approach 11 and will definitely work. Something else 10 you can do though is to include additional 9 CSS on the exceptional pages.

For example 8 you can have an allpages.css that is include 7 in all pages and contains the CSS:

.element1 {
    font-size: 14px;
}

Then you 6 can have a separate CSS file called exceptions.css 5 that contains:

.element1 {
    font-weight: bold;
}

This works because when multiple 4 rules are defined for the same selector 3 the rules are merged together. Using this 2 technique you wouldn't have to modify the 1 class values for HTML elements.

Score: 0

Syntax like that used in http://lesscss.org/
I hope you'll 1 find some useful staff there

More Related questions