Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

CSS will not work

by tu (Initiate)
on Aug 06, 2001 at 22:32 UTC ( [id://102543]=perlquestion: print w/replies, xml ) Need Help??

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

When I try to reference an external CSS file, it does not work. My header code for HTML output looks something like the following:
print header; print<<END; <html><head> <link rel="stylesheet" href="member_style.css" > </head>
---------- I have also tried to do it these ways:
print header; print start_html( -style=>{-src=>'http://localhost/cgi-bin/template/h +ardcode/member_style.css'} ); print start_html( -style=>{-src=>'./member_style.css'} ); print start_html( -style=>{-src=>'member_style.css'} );
thanks.

tu

Replies are listed 'Best First'.
Re: CSS will not work
by Trimbach (Curate) on Aug 06, 2001 at 22:58 UTC
    You need to give src a full URL, not a path. So this should work:
    print start_html( -style=>{-src=>'http://www.somewhere.com/member_sty +le.css'} );

    Gary Blackburn
    Trained Killer

      A full URL? That's news to me. I use the following code. Looking at the code here, I may be using an ancient idiom that has since been superceded, but I offer it for completeness' sake.

      use CGI qw/Link/; my $q = new CGI; print $q->header(), $q->start_html({ -title => 'title of my page', -head => Link({-rel=>'stylesheet', -type=>'text/css', -href=>'/fo +o.css'}), });

      I sorta like this, because it reminds me just what exactly I'm asking the script to emit.

      update: I typed the above code in from memory, and in the original incarnation, I wrote -href=>'foo.css'. I checked some production scripts, and what I do In Real Life is -href=>'/foo.css'. This is not a relative reference (correct me if I am wrong), in that I am not using -href=>'../foo.css' -- I guess you could say it's absolute on the current server.

      I was taking issue with the explicit http://... I don't believe that that is necessary, and it makes it a smidgin easier to transfer the script from one host to another.

      --
      g r i n d e r
        Well, yeah, but some web servers don't resolve relative pathnames nicely, and it's generally not a good idea to put your css files in the same directory as your executable scripts (as someone else already pointed out.) In such cases, a fully qualified URL is your friend.

        Gary Blackburn
        Trained Killer

Re: CSS will not work
by miyagawa (Chaplain) on Aug 06, 2001 at 23:24 UTC
    Can your "member_style.css" be fetched via HTTP? For example with Apache, /cgi-bin/ is ScriptAliased, so any static files on that directory can't be accessed directly.

    Put it in static DocumentRoot directory instead. Hope this helps.

    --
    Tatsuhiko Miyagawa
    miyagawa@cpan.org

Re: CSS will not work
by zeno (Friar) on Feb 24, 2003 at 12:29 UTC
Re: CSS will not work
by wardk (Deacon) on Aug 07, 2001 at 00:00 UTC

    probably a silly question, but usually CSS files are in an html directory, and code in cgi-bin (or similar) appears you are looking in the same place as the code...

    # assuming it's in the root... print start_html( -style=>{-src=>'/member_style.css'} )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://102543]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found