Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / September 2005



Tip: Looking for answers? Try searching our database.

Possible to use two CSS files for one page?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
g@risky-biz.com - 28 Sep 2005 20:23 GMT
I'd like to have a CSS file for everything that's common to my site,
and other CSS files that are specific to certain pages or groups of
pages. When a page loads, it would load in BOTH the General CSS and the
specific CSS file for that page. As long as none of the selector names
were the same on both, could the page follow the styles set out in both
files?

Greg Guarino
David Dorward - 28 Sep 2005 23:12 GMT
> I'd like to have a CSS file for everything that's common to my site,
> and other CSS files that are specific to certain pages or groups of
> pages. When a page loads, it would load in BOTH the General CSS and the
> specific CSS file for that page. As long as none of the selector names
> were the same on both, could the page follow the styles set out in both
> files?

Yes. It could do that even if selectors were the same. The usual rules for
the cascade order apply.

Signature

David Dorward       <http://blog.dorward.me.uk/>   <http://dorward.me.uk/>
                    Home is where the ~/.bashrc is

Robi - 28 Sep 2005 23:18 GMT
g at risky-biz.com wrote in message news:1127935385.754379.223000@z14g2000cwz.googlegroups.com...
> I'd like to have a CSS file for everything that's common to my site,
> and other CSS files that are specific to certain pages or groups of
> pages. When a page loads, it would load in BOTH the General CSS and the
> specific CSS file for that page. As long as none of the selector names
> were the same on both, could the page follow the styles set out in both
> files?

yes, as follows:

<LINK REL="stylesheet" TYPE="text/css" HREF="/library/shared/css/general.css">
<LINK REL="stylesheet" TYPE="text/css" HREF="/library/shared/css/specific.css">

besides, you can purposedly "modify" a *general* style in the *specific* stylesheet.

I'd suggest the following to read:

http://www.w3.org/TR/REC-CSS1#containment-in-html

http://www.w3.org/TR/REC-CSS2/cascade.html#at-import
Greg G - 29 Sep 2005 00:11 GMT
>g at risky-biz.com wrote in message news:1127935385.754379.223000@z14g2000cwz.googlegroups.com...
>> I'd like to have a CSS file for everything that's common to my site,
[quoted text clipped - 16 lines]
>
>http://www.w3.org/TR/REC-CSS2/cascade.html#at-import

Thank you. Here's why I want to do this.

I have a number of photo gallery pages that will have the same overall
look, but a different background image for the TOC area and possibly
some other slight changes. I started out doing this by copying the CSS
file, making the changes, and giving it a new name. But I realized
that should I want to do something global, change the background from
black to white for example, I'd have to do that on a bunch of
different files.

Following your advice I will soon make up a stylesheet that has all
the common elements and several others with the variable stuff.

Greg Guarino
Robi - 30 Sep 2005 05:02 GMT
>> g at risky-biz.com wrote in message news:1127935385.754379.223000@z14g2000cwz.googlegroups.com...
>>> I'd like to have a CSS file for everything that's common to my site,
[quoted text clipped - 18 lines]
>>
> Thank you. Here's why I want to do this.

you're welcome

> I have a number of photo gallery pages that will have the same overall
> look, but a different background image for the TOC area and possibly
[quoted text clipped - 6 lines]
> Following your advice I will soon make up a stylesheet that has all
> the common elements and several others with the variable stuff.

I don't know exactly how the '@import' rule behaves with relative urls

Let's say yor page is located in /www/root/galleria
(galleria has a subdirectory css -> /www/root/galleria/css)
the global.css is located in /www/root/css
if you have other pages in other directories i.e.
/www/root/gallerib (including subdirectory css)
/www/root/galleric (the css subdirectories are not necessary, but they
give a clean slate and order ;-)

Now for all galleria pages you have a specific style that differs from
the global.css. let's call it common.css and place it in the subdirectory
/www/root/galleria/css

now you can have the following lines in your html page:
<link rel="stylesheet" type="text/css" href="/css/global.css">
<link rel="stylesheet" type="text/css" href="css/common.css">

note the difference in the hrefs (one is "absolute" and one is "relative")

I somehow think that the same is possible with the '@import' rule
where you would only need the global.css link line, and in global.css
you would have the following line:
@import url(css/common.css);
but here is where I am not sure about the rule.
Wwill the browser think common.css is in /css/css/common.css
or since gallery.html is in /galleria/gallery.html by linking to the global.css
stylesheet in /css/global.css will the '@import' rule in global.css be
understood as /galleria/css/common.css

or instead, if that doesn't work
<style type="text/css">
 @import url(/css/global.css);
 @import url(css/common.css");
</style>

of course, you could even go further and add page specific styles
<link rel="stylesheet" type="text/css" href="/css/global.css">
<link rel="stylesheet" type="text/css" href="css/common.css">
<style type="text/css">
 h1 { color: blue }
</style>

to make it a bit more complicated, add media types ;-)
http://www.meyerweb.com/eric/articles/webrev/200001.html

BTW, if you're going to have your gallery pages sent as XHTML then AFAICR
you will need to have all your tags and selectors defined in lowercase.

( http://www.w3.org/TR/REC-CSS2/selector.html#q1 second paragraph )

I am honestly very unfamiliar with the '@import' rule, and might be giving
a completely wrong advice here, so if someone else can shed some light on
anything that I have misunderstood, It would be greatly appreciated :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.