yvan has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I am starting to use css with some perl cgi scripts. In the css file body is defined like that:
BODY {
background-color: #0e7aef;
color: white;
font-family: sans-serif;
}

The cgi script contains these declarations:
$q -> start_html(-title => "$title", -style => { -src => 'mycss/mtannot.css', -type => 'text/css', -media => 'screen' }),

But the body background color stays always white. I tried to declare in start_html -class=>body with no effect.
Is it possible to use a body class in css with perl cgi? Or should I use backgroud-color within the start_html function?
Thanks for your help. yvan

Replies are listed 'Best First'.
Re: cgi and css, body tag not recognize
by Joost (Canon) on Jun 14, 2007 at 19:57 UTC
    1. You must print() the output of $q->start_html.

    2. Are you sure the href to the css is correct?

    This works:

    test.pl:

    #!/usr/bin/perl -w use strict; my $q =CGI->new; print $q -> start_html(-title => "bla", -style => { -src => 'test.css' +, -type => 'text/css', -media => 'screen' });
    test.css is your css.

    $ perl -MCGI test.pl >test.html Open test.html in firefox.

      when the .html is display in firefox, the background colour is not changed. All the others classes in the css file work fine but not the body.
Re: cgi and css, body tag not recognize
by moritz (Cardinal) on Jun 14, 2007 at 19:51 UTC
    Check the HTML source that the CGI script produced.

    Does it contain the correct reference to the CSS file?

    Can you manually access that CSS file manually with that given URL?

      HTML and CSS are correct according to the W3C validators.
      Yes, other CSS classes work fine, just the BODY is problematic.
        Try a background-color: #0e7aef !important; once (and write body in lower case, just in case you ever want to switch to xhtml), to rule out some interference with other declarations.

        And an URL to the problematic page might be helpfull so that we can see for ourselves.

        BTW which browser are you using? For development you should be using a standards compliant one (opera, firefox), not IE ;-)