11 replies [Last post]
smirkingdude
Offline
Enthusiast
Last seen: 15 years 5 weeks ago
Timezone: GMT-4
Joined: 2007-04-07
Posts: 61
Points: 0

Suppose there is a website-wide CSS file, main.css, in the main directory and there is a directory for guestbook, Talkback, which contain alot of PHP files and some CSS files.

Scenario #1
If I design a web page in the main directory that links to specific CSS file(Drunk and specific PHP files(Drunk from Talkback directory.

What's the CSS way of linking to specific CSS files from different directory?

Scenario #2
If I decide to design a webpage in Talkback directory and want to have main.css linked to this web page along with CSS files from within Talkback directory. What is the CSS way of doing this?

"Imagination is more important than knowledge"
Albert Einstein

Tags:
Ed Seedhouse
Ed Seedhouse's picture
Offline
Guru
Victoria British Columbia
Last seen: 1 year 31 weeks ago
Victoria British Columbia
Timezone: GMT-8
Joined: 2005-12-14
Posts: 3570
Points: 675

smirkingdude wrote:What's

smirkingdude wrote:
What's the CSS way of linking to specific CSS files from different directory?

The CSS way is with an @import rule.

Or you can do it with html using the "link" tag.

As for the exact path description that depends on the server and where your files are.

Ed Seedhouse

Posting Guidelines

Watch out! I am carrying irony, sarcasm and satire, and know how to use them.

smirkingdude
Offline
Enthusiast
Last seen: 15 years 5 weeks ago
Timezone: GMT-4
Joined: 2007-04-07
Posts: 61
Points: 0

*scratching my head* :-?

Ed,

Thanks for answering to the question under scenario #1 Smile

I also need to know:

Scenario #2
If I decide to design a webpage in Talkback directory and want to have main.css (from main directory) linked to this web page along with CSS files from within Talkback directory. What is the CSS way of doing this?

----------------------------------------------------------------------------------------------
File system used in this example

Main Directory

  • main.css

  • webpage 1

  • Talkback directory*

  • images directory
  • Talkback Directory* (inside main directory)

  • PHP file

  • another PHP file

  • CSS file

  • another CSS file

  • webpage 2
  • Scenario 1 applies to webpage 1
    Scenario 2 applies to webpage 2

    "Imagination is more important than knowledge"
    Albert Einstein

    ClevaTreva
    ClevaTreva's picture
    Offline
    Guru
    A hilly place, UK
    Last seen: 3 years 47 weeks ago
    A hilly place, UK
    Joined: 2004-02-05
    Posts: 2902
    Points: 0

    Hi Putting ../ in front of

    Hi

    Putting ../ in front of the filename moves up one directory

    Going up two directories is ../../

    and so on, then you can drill back down using the directory names

    Hugo
    Hugo's picture
    Offline
    Moderator
    London
    Last seen: 7 years 37 weeks ago
    London
    Joined: 2004-06-06
    Posts: 15668
    Points: 2806

    You just link to the files

    You just link to the files it's a path problem rather than anything specific to CSS, Ed pretty much covered it didn't he?

    Pages in the talkback directory could have their own main style link and in that stylesheet file you could @import the other style file from elsewhere on your server, which is one way of doing things or just link both files in the head.

    Hugo.

    Moving to 'Off Topic'

    Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
    ----------------------------------------------------------------
    Please post ALL your code - both CSS & HTML - in [code] tags
    Please validate and ensure you have included a full Doctype before posting.
    Why validate? Read Me

    smirkingdude
    Offline
    Enthusiast
    Last seen: 15 years 5 weeks ago
    Timezone: GMT-4
    Joined: 2007-04-07
    Posts: 61
    Points: 0

    Hmm... see if I understand you...

    ClevaTeva,

    Let's see if I understand you correctly. Under scenario #2, I enter this in XHTML:

    and on a stylesheet, type this:

    @import url("../main.css");

    Am I mistaken?

    "Imagination is more important than knowledge"
    Albert Einstein

    ClevaTreva
    ClevaTreva's picture
    Offline
    Guru
    A hilly place, UK
    Last seen: 3 years 47 weeks ago
    A hilly place, UK
    Joined: 2004-02-05
    Posts: 2902
    Points: 0

    That looks right

    That looks right

    Hugo
    Hugo's picture
    Offline
    Moderator
    London
    Last seen: 7 years 37 weeks ago
    London
    Joined: 2004-06-06
    Posts: 15668
    Points: 2806

    Always remember though that

    Always remember though that paths in stylesheets are relative to the stylesheet location.

    Your other option is to specify absolute paths that is from 'Root' these are prepended with a '/' slash which denotes document root

    Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
    ----------------------------------------------------------------
    Please post ALL your code - both CSS & HTML - in [code] tags
    Please validate and ensure you have included a full Doctype before posting.
    Why validate? Read Me

    Ed Seedhouse
    Ed Seedhouse's picture
    Offline
    Guru
    Victoria British Columbia
    Last seen: 1 year 31 weeks ago
    Victoria British Columbia
    Timezone: GMT-8
    Joined: 2005-12-14
    Posts: 3570
    Points: 675

    smirkingdude wrote:Am I

    smirkingdude wrote:
    Am I mistaken?

    Don't use any quotes between the brackets for the @import statement.

    Ed Seedhouse

    Posting Guidelines

    Watch out! I am carrying irony, sarcasm and satire, and know how to use them.

    ClevaTreva
    ClevaTreva's picture
    Offline
    Guru
    A hilly place, UK
    Last seen: 3 years 47 weeks ago
    A hilly place, UK
    Joined: 2004-02-05
    Posts: 2902
    Points: 0

    Ed Seedhouse

    Ed Seedhouse wrote:
    smirkingdude wrote:
    Am I mistaken?

    Don't use any quotes between the brackets for the @import statement.

    I use quotes when I use @import. It hides the stylesheet from some older browsers.

    Hugo
    Hugo's picture
    Offline
    Moderator
    London
    Last seen: 7 years 37 weeks ago
    London
    Joined: 2004-06-06
    Posts: 15668
    Points: 2806

    But it trips up IE Mac which

    But it trips up IE Mac which although old and decrepit and no longer supported did handle CSS as well as IE5+ if not better and I'm not sure we want to completely deprive it of any styles whatsoever?

    Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
    ----------------------------------------------------------------
    Please post ALL your code - both CSS & HTML - in [code] tags
    Please validate and ensure you have included a full Doctype before posting.
    Why validate? Read Me

    ClevaTreva
    ClevaTreva's picture
    Offline
    Guru
    A hilly place, UK
    Last seen: 3 years 47 weeks ago
    A hilly place, UK
    Joined: 2004-02-05
    Posts: 2902
    Points: 0

    Ah That was why I used

    Ah

    That was why I used it.

    I was sticking a couple of fingers up to the Mac and the IE users on it. Must remember that!