Solved

Inheritance in CSS

Posted on 2001-07-06
13
399 Views
Last Modified: 2008-03-10
Hi all ,
Please forgive me about this question since i'm asking just because I don't have the time to look for the answer and I hope someone will know the answer without spending time on it.

So , for the question  , Is there a way to inhert CSS properties from one class to another ?

For example :

FURNITURE  
  {
  made-off:wood;
  }

DOOR
  {
  typeof: "FUNRNITURE";
  shape:like-square-but-not;
  }

and when using this CSS block , DOOR will be "made-off" wood.

Does someone knows of anything similer ??

Please don't get into the "inherit" peropertie since I am familier with it , and it has nothing to do with my questions.

Thanks in advance,

                  Avner.
0
Comment
Question by:avner
  • 6
  • 4
  • 3
13 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
The short answer is no, but everyone knows I hate short answers.

So while it is not possible to use typing for inheritance, you can
use scoping, which probably already understand:

  .furniture {made-of:wood}
  #door {shape:like-square-but-not}
  .funiture #door {trim-type:brass}

anything with an id of "door" has the shape attribute, but if
contained in an element of class furniture it is also made of wood and
has brass trim.

I'm not sure that is what you are looking for, but that is about as
close as you can get to direct casting of the attributes based on the
value of another class.

HTH

Cd&
0
 
LVL 14

Author Comment

by:avner
Comment Utility
CD,
your suggested answer is what I already know.
I'm hoping to read something that I didn't know , I will leave this question open a little more and if I won't receive any new insights , I'll accept your answer.
thanks for the help.

avner.




0
 
LVL 8

Expert Comment

by:klykken
Comment Utility
hmm what about:

.furniture, .door  {made-off: wood;}
.door { shape:like-square-but-not; }

It's not inheritance, just another way of structuring your css rules.
--
klykken
0
 
LVL 14

Author Comment

by:avner
Comment Utility
klykken ,
This is what I call a new insight !

But...
The reason why I've never tried this way of declaring CSS was because it looks weird to declatre one rule twice.

Are you 100% that on all platforms and all browsers , CSS will allow this usage ?
Have you ever notice anything about it in the W3C CSS recommandation ?


avner.

0
 
LVL 8

Accepted Solution

by:
klykken earned 106 total points
Comment Utility
avner,
You don't have to be afraid to use this structure of css.
This is called grouping and is quite common.
You would maybe declare a font this way for your site:
body, table, td, div, span, p {font-family:  Arial, Helvetica, sans-serif;}

This is part of the CSS standard as seen here:
http://www.w3.org/TR/REC-CSS2/selector.html#grouping

In the web-development company I work for we use this way of declaring CSS every day, so I think you can relax. Works at least on 4 browsers and up.
Thats the browsers we test our sites on anyway.

--
klykken
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
It's a little strange, but it works in IE.  Don't have Netscrap here to try it but there is no reason for it to not work on any browser that supports CSS.  It is just a different way of building the cascade.  Good approach klykken.  I would never have tried it that way.  Maybe I'm too conventional.

Cd&

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Author Comment

by:avner
Comment Utility
klykken ,
Thank you very much for our help , although this is not inheritance , this way is good enough to solve my problem since the whole inheritance thing came originally from the fact that I wanted to be able to declare a "all-around-font"

and I can achive this using the grouping thing.

0
 
LVL 14

Author Comment

by:avner
Comment Utility
btw - Cd , thanks for your help, sorry I couldn't help incearsing your points status in this area , I know you need it....:)
0
 
LVL 8

Expert Comment

by:klykken
Comment Utility
avner, glad to be of quick help, and thanx for the A :)
..and don't wory about COBOL, he has enogh points already ;-)

cobol: I tried some solutions with wildcards (*) until it finally struck me to use grouping this way, funny how CSS let you conceptually find different solutions to things. I would never have thought of the set of rules in your first comment.
--
klykken
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
I think I have gotten to a leve where points are not real important.  Good Qs with interesting ideas is where the fun is.  Thanks for posting this avner it makes a good addition to the PAQ.  This TA is only 1 year old but it has really great solutions in it.

Scoping is something I use all the time, and groupings as well.  I just never thought about declare the same class twice for different attribute sets.  Something else to add to the arsenal. :^)

Cd&
0
 
LVL 14

Author Comment

by:avner
Comment Utility
I'm happy to see that I am not the only one that learned.

Thanks for your help.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Hmmm... klykken move up into the top ten with this Q passing several other experts including avner.

Cd&
0
 
LVL 14

Author Comment

by:avner
Comment Utility
... and is well deserved it....:)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now