From: Paul Lutus Date: 2006-09-12T17:55:38+09:00 Subject: Re: cgi scripts and external css Peter Seidel wrote: > Consider this CGI script: > > #!ruby > require "cgi" > cgi = CGI.new("html4") > cgi.out { > CGI.pretty( > cgi.html { > cgi.head { cgi.title{"Example"}+" type=\"text/css\" href=\"example.css\">" } + > cgi.body{"This should have a green background"} > } > ) > } > > with this example.css, both residing in the same directory: > > body { > background-color: #00ff00; > } > > it produces this html output: > > "http://www.w3.org/TR/html4/strict.dtd"> > > > > Example > > > > > This should have a green background > > Is this HTML (or the script that generates it) located in the same directory as your CSS example file? If not, it won't work. When there is no path given in "href", just a filename, the target file must reside in the same directory as the source file, whether that is a CGI script or a Web page. You don't show how you are making the generated HTML available to the browser. It (or its generating script) must be located in the same directory as the example CSS, or a path must be provided as part of the "href" address. > > Perfectly fine, it seems. The only problem is, that the background isn't > green, it's white (Firefox' default color, on my system). > However, if I save the html-source to a static example.html, put in the > same directory as my example.rb and open it in the browser, the css is > correctly applied and the background turns green. And that is the only way this example would work. The script that generates the HTML must be located in some specific way with regard to the CSS file, in order for the CSS files to be located by the browser. > > It works if I put the css directly in the example.rb like this: No need for that. /... > Where lies the problem in my script? The problem is not your script per se, it is in the part you don't show -- how you locate it with respect to the CSS file. -- Paul Lutus http://www.arachnoid.com