1

I have a specific css class "styled" which gives glass effect to the various divisions. The site is at http://www.rohanjain.in/. I have various html5 tags which use the glass effect from the css class defined. Is there any way to define in the .css so that my header, footer, article tags use the class "glass" automatically, i.e. they inherit from this class. I am trying to do to decrease the size of css and html. Right now these tags are provided attribute class="stlyed" from html. But is there any way to do this only using css.
I really don't want to do something like this:

article, footer, header{
    ...css definations... 
}

I want to use browser detection and define class glass in some other .css according to the features supported while keeping the size minimal.


Update 1: This is the source of css http://www.rohanjain.in/media/css/style.src.css. The size of styled class is high because of multibrowser effect definations.

Update 2: It seems there is no simple way to achieve inheritance of classes, so I am finally using class="stlyed" in the html elements to achive this.

2
  • fwiw, I wouldn't really worry about the size of your CSS as motivation for doing this - CSS is a relatively light part of any payload anyway and very cacheable. Commented Nov 12, 2010 at 15:22
  • hmm...I am just trying to see the limits I can reduce my webpage's size, so trying to implement most new features (html5, css3) and reduce use of images, javascripts. Commented Nov 12, 2010 at 15:24

4 Answers 4

1

Think about this from a CSS perspective. How is your CSS meant to know that you have some tags which are in some way special if you're not prepared to tell the CSS about them explicitly and you're not going to classify your markup implicitly?

The best solution I believe is to classify your markup (but not using something as unsemantic as "glass") but the explicit element based CSS is perfectly acceptable.

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

Comments

1

There is a tool called LESS that will do exactly that:

Can a CSS class inherit one or more other classes?

2 Comments

LESS still compiles to normal CSS, but the OP said he wanted to reduce the size of his CSS.
The change in size is negligible. The only other way would be to define the three tags as the OP said, which would increase the size of the CSS anyway.
1

No, you either have to define them together:

article, footer, header, .glass {
    ...
}

so that those tags have the same styles as the "glass" class, or you have to use JavaScript to dynamically add the "glass" class to those elements.

Comments

0

If I understand you correctly, the way that you show

article, footer, header{
    ...css definations... 
}

really is the only, and most correct, way to do this. I don't understand why you don't want to use it, or what other kind of definition you are looking for?

Comments

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.