473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CSS class hierarchy syntax

Atli
5,058 Expert 4TB
Hi.

Say I have these three classes:
Expand|Select|Wrap|Line Numbers
  1. .Paragraph { width: 200px; margin: auto; }
  2. .Paragraph .Header { display: block; font-weight: bold; }
  3. .Paragraph .Text { display: block; font-size: 90%; }
Is there a way to rewrite that syntax so that I can omit the parent class (.Paragraph) in the last two without making them global?

Like, for example:
Expand|Select|Wrap|Line Numbers
  1. .Paragraph { 
  2.   width: 200px; margin: auto;
  3.   .Header { display: block; font-weight: bold; }
  4.   .Text { display: block; font-size: 90%; }
  5. }
This won't work, but is there something else that might?

I've been trying to search for an alternate syntax, but all I can find are examples of the basic syntax. I even tried going through the W3C documentation but couldn't find anything useful.

I'm just wondering, because I have a lot of classes that need to be nested pretty deep and right now something like 90% of the CSS file seems to be nothing but repeated parent classes. Seems like an awful waste of bandwidth :P
Dec 27 '08 #1
4 13852
drhowarddrfine
7,435 Expert 4TB
Yes.



:)

Back in a little bit.
Dec 27 '08 #2
drhowarddrfine
7,435 Expert 4TB
You can look into selectors but I'm not sure you'll find much relief. Classes are meant to be somewhat global themselves so if you are getting where a class in one instance is different than all other classes, then you should be using an 'id'.
Dec 27 '08 #3
Atli
5,058 Expert 4TB
Thanks for that.

It's not that the classes themselves are unique to an instance. It's more, I have a lot of very similar, if not identical, HTML and CSS class structures whose only difference is the CSS styles.

Like, for example, blog entries and news entries. Those are basically the same things, except that the CSS *styles* are different. I reuse the HTML for both, only swapping out the root CSS class.

Many of the deeply nested classes are unique to the root class tho, so I could probably use the wild-card char to cut down the repeating classes a lot.

That is:
Expand|Select|Wrap|Line Numbers
  1. .something { color: #00F; }
  2. .root1 .first .second .third .something { color: #F00;  }
  3. .root2 .first .second .third .something { color: #0F0 }
  4.  
Could in many cases turn into:
Expand|Select|Wrap|Line Numbers
  1. .something { color: #00F; }
  2. .root1 * .third .something { color: #F00;  }
  3. .root2 * .third .something { color: #0F0 }
  4.  
That might cut down the size of the CSS file a bit.
Dec 28 '08 #4
drhowarddrfine
7,435 Expert 4TB
Or #something1 and #something2 and move the common attributes further up the cascade but without the big picture it's hard to say. Selectors might be more your answer, don't know.
Dec 28 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
2
by: Matt | last post by:
Hello, I would like to generate what I call an "overall class hierarchy" in UML automatically derived from my C++ code source. An example of what I seek: ...
7
by: Robert W. | last post by:
I've just been reading all about the Singleton class and understand how to implement and use it but I cannot understand why one NEEDS to use it instead of just declaring a class and implementing...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
2
by: Alex Maghen | last post by:
I have a site where most of the pages will have a common "shell" or layout. There will be an outer table which will hold HTML elements but which will *also* hold UserControls (Global Nav, etc.)....
3
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this...
14
by: Jo | last post by:
Hi, Is there a generic way to access the (virtual) functions in the base class of a class? Like in: if (!this->Foo(something)) return(((Base*)this)->Foo(something)); // for a normal member...
0
by: chris.bahns | last post by:
Hello All, I am fairly new to creating custom attributes, and want to get a better feel for how they should be named. We have a class hierarchy, with a base class called "SequenceCommand". This...
2
by: K Viltersten | last post by:
Suppose there is the following class structure. class S {...} class A : S {...} class B : S {...} class A1 : A {void m(){...}} class B1 : B {void m(){...}} class B2 : B {...} Just to clarify...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.