473,403 Members | 2,071 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,403 software developers and data experts.

Class Dependant CSS Import?

Hi Everyone, it's my first post, so please be kind... :-)

I've had a look through the board and although CSS importing has been covered in quite a few topics, I have what I think is a unique challenge, which is to import a specific stylesheet depending on the class set in my body tag. Let me explain.

I am using the usual <link> tag to import my "screen" stylesheet into each of my pages. This provides basic structure and formatting, which I've put together specifically for older browsers.

This layout is complimented by the import of another sheet called "styles" from within "screen", which to provides section-specific colour schemes and a few bells and whistles for newer browsers. As the @import function means that the new styles are hidden from NN4 and IE4, if someone visits using an ancient browser, they get one view; if they visit with something newer, they get antother - simple, eh?

Now, here's the difficult bit. I have set my body tag on each page with a different class, which when set to a specific name such as "home", tells the menu which item to show as active and which section-specific colours or formatting to display. The menu info comes from my "screen" stylesheet, the colour and formatting from "styles".

As you can imagine, a single stylesheet covering all possible colour schemes and formatting for each section (8+) would be - in fact, is - huge, so I wanted to know if any one has any suggestions for importing a stylesheet depending on the body class that has been set?

One last thing, I realise I could just manually link section-specific stylesheets to pages (!!!) but I'd really like to automate the process as it's quite possible that I won't be the only person making future changes to the site.

Thanks in advance for your help,


Mo
Jun 29 '06 #1
2 2354
Banfa
9,065 Expert Mod 8TB
As you can imagine, a single stylesheet covering all possible colour schemes and formatting for each section (8+) would be - in fact, is - huge, so I wanted to know if any one has any suggestions for importing a stylesheet depending on the body class that has been set?
How big (in kbytes) is huge?

Remember that if all the pages are linked to the same style sheet what should happen is that that style sheet will be downloaded with the first page but after that the users browser should just access it from the browser cache (this is 1 of the stated advantages of style sheets in CSS files).

Personally I don't think what you want to do is actually possible, well may be using javascript but then you are just putting in another thing that can go wrong/be switch off.
Jun 29 '06 #2
How big (in kbytes) is huge?

Remember that if all the pages are linked to the same style sheet what should happen is that that style sheet will be downloaded with the first page but after that the users browser should just access it from the browser cache (this is 1 of the stated advantages of style sheets in CSS files).

Personally I don't think what you want to do is actually possible, well may be using javascript but then you are just putting in another thing that can go wrong/be switch off.
Banfa, thanks for your response.

To answer your question, the style sheet was sitting at around 17k - I normally stick to a max of 10k, with most of mine hitting between 4-8k each.

In order to decrease the file size ensure a reliable graceful degrade of some features I have gone back to my initial thought, which was to use a master style sheet that provides a very basic level of formatting/colour, then use "@import" to bring in the page elements I spoke about in my post.

Whether I cascade this function to form a small chain of stylesheets, I'm not sure but I'll have fun trying.

Regardless, I've tested out this approach and it seems to provide a stable solution. I suppose I'll have to keep wishing for some form of selector-based CSS import functionality in a future version of the CSS standard!

Thanks very much for your sanity check,

M
Jul 3 '06 #3

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

Similar topics

2
by: Tobias Pfeiffer | last post by:
Hi! I want to write a package of modules that deal with mathematical graphs. So my plan is to have a main.py file where the basic operations are done, like reading the file and creating an...
2
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
10
by: lkrubner | last post by:
I killed last night and a good chunk of today trying to figure out this one particular attempt to get a class and initialize it. My code is using a class method called getObject to include() a file...
4
by: Tomas Ukkonen | last post by:
Hi I'm currently trying to make my old code to compile with new gcc 3.4.0. It compiles correctly in 3.3.3 so I'm not sure if this is compiler bug or not. Code very close to a example below...
9
by: Larry Woods | last post by:
I have a method in my base class that I want ALL derived classes to use. But, I find that I can create a "Shadow" method in my derived class that "overrides" the method in my base class. Can't...
2
by: m.tyka | last post by:
Hello, I have the following code --- template < typename T> struct Base { T base_member; };
6
by: py_genetic | last post by:
Is this possible or is there a better way. I need to create a new class during runtime to be used inside a function. The class definition and body are dependant on unknows vars at time of exec,...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.