tags:

views:

69

answers:

4

I'm working with software that uses a web interface, but this software apparently doesn't support linking css files in the usual way:

<link href="style.css" rel="stylesheet" type="text/css">

The software renders the pages directly, it doesn't go through a "real" web server. Are there alternative ways to link a css file that I might try?

+4  A: 

Try this:

<style type="text/css">
  @import "relativePathToYourCSSFile.css";
</style>

Edit: you can also make all of your css declaration in that style tag, which wont require the page to 'go looking for' the other files (which it would need a server to do i believe). For example:

<style type="text/css">
    #someCssId {
        someStyleProp:someValue;
    }
</style>
Dfowj
Thanks, but unfortunately this didn't work either. It is an unusual situation so all I can do is trial and error...
Alan
Ultimately trying to link the external file so that it can be edited in one place.
Alan
What is the software you're using? That information would probably help greatly, for instance if someone here has used it before and gotten around this problem
Dfowj
Cinema 4D Net Render Server, working on a custom theme for it:http://slct.tv/still.php?id=netrendergraphite
Alan
+1  A: 

if you have an existing css file, you can place an @import at the bottom of the file.

You could inline styles into html using the <style> tag and then place the css or an @import inline.

James Westgate
+2  A: 

Well, if JavaScript isn't sanitized out and you're up for a bit of a hack:

<script type="text/javascript">
(function () {
    var h, l, addcss;
    if(h = document.getElementsByTagName('head')[0]) {
        addcss = function (url) {
            l = document.createElement('link');
            l.setAttribute('type','text/css');
            l.setAttribute('rel','stylesheet');
            l.setAttribute('href',url);
            return h.appendChild(l);
        };
        addcss(cssfile1);
        addcss(cssfile2);
                    ...
        addcss(cssfileN);
    }
})();
</script>

Or you could directly manipulate the document.styleSheets object...

Weston C
No luck on this one either, but just to verify that I am using it correctly, my addcss function would look like this right: addcss('style.css');Again, I tried this with multiple paths as well, including /style.css, style.css, full path, etc. No luck :(
Alan
Yeah, the parameter to addcss is the url of a css file -- whatever you'd put in the href attribute of a link tag.You might want to add an `alert` (or if you're using a browser which supports it, `console.log` statement) to addcss and/or the wrapping anonmymous function to verify they're getting called. If not, then JavaScript is getting sanitized and there's little hope of this tack working. If so, we might be able to try some other things.
Weston C
A: 

I do this all the time when working on a page locally, no "real" web server is needed, and it works just fine. You do have to be careful about absolute vs. relative paths, for example href="site.css" vs. href="/styles/site.css" the first works fine with a file:/// url but the second refers to the root of the local filesystem, which is probably not where the css file actually is.

Can you post an actual tiny HTML page and CSS file that doesn't work for you?

Stephen P
Yeah, it's odd because I can make it work if I just open the file directly, but for some reason when the software serves the page the CSS is no longer linked.
Alan