SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using @import with other file extensions

    Is it possible to use @import with a file extension other than .css? For example:

    <style type="text/css">@import url(all_css.php);</style>

    I have a style sheet that's a .php file, in which some values (body background color, text color, font size, etc.) are pulled from a MySQL database. The purpose is to create a PHP form page with which I can change those values.

    When I use <LINK> to link to the file, it works, but not @import, which I'd like to use. Does it just not work or am I missing something?

    Thanks for any input.

  2. #2
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to have to tell the browser that the .php file is indeed a CSS file when you send it to the browser. I think you can do that by putting something like this in your "all_css.php" before you send any content to the browser:
    Code:
    header("Content-Type: text/css");
    When you use the link method, you've already told the browser what content type the file is (i.e. "type=text/css").

    ~~Hope This Helps

  3. #3
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks!

    Ian, you're a life-saver. That worked like a charm. Thank you.

  4. #4
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shucks, you're embarrassing me... I guess I'm better at PHP than I thought. ;-)

    Anyway, I'm just happy you're using CSS.

    ~~You're Welcome

  5. #5
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it was boggling me why it wasn't working like LINK did. But then, what is the 'type="text/css"' for in the STYLE tag when you use @import?

    CSS is the way of the future! I'm in the middle of building a table-less site, which I hope to feature in Winged Spider's topic (before it's too late) - saw you over there too.

  6. #6
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, I'm all over the place. :-)
    _____

    Putting the type attribute in the <style> tag just tells the browser that you're using CSS as the style sheet language for that block. For all the it knows, you're using XSL or something else. The browser's supposed to default to CSS for authors who don't include the type attribute, though. I guess you can technically import some other style sheet language through @import. Though, I would advise against using different style sheet languages in a single document when XSL and others become widely supported.

    PHP files are sent by default as HTML files to the browser. Since HTML is not a style sheet language, CSS interpreters don't know what to do with it. You probably should always explicitly tell (via header("Content-Type: */*")) the browser what type of file your sending if you're using PHP for anything other than HTML output.
    _____

    A table-less design, that's pretty cool! If that topic does die, you can always resurrect from the dead. I'm interested as to what you going to come up with. Good Luck!

  7. #7
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, well, you can read my preachings on CSS there (though, now that I've revealed my ignorance about @import, who's gonna listen . Thanks for the explanations - very helpful and make perfect sense.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •