简体   繁体   中英

Perl CGI script with css

I am using a external css for my CGI web form but I can't get the .css to take to the page. Is there a certain way a external css needs to be called. I tried:

<link rel="stylesheet" type="text/css" href="../styles/archiveRequest.css" media="screen" />

which has not been working. I have tried moving the css in the same folder as the .cgi with still no results.

The href attribute needs to be in relation to the page you're viewing in your browser. For example, if your URL is http://www.example.com/cgi-bin/mypage.cgi then, with your above code, your CSS file needs to be viewable in a browser at http://www.example.com/styles/archiveRequest.css . Try loading it up directly in your browser using the direct URL. Also take a look at your server logs, and you'll probably find 404 errors showing where the file is trying to be loaded from.

I know this was asked quite a while ago, but I had the same problem today and spent hours looking for an answer. This is what worked for me:

If my cgi script is /var/cgi-bin/test.cgi , putting my style.css file in the same directory did not work. Apparently this makes it get treated like a script, which it isn't. I moved my style file to /var/www/styles/style.css and made it non-executable (but readable).

In a browser, I was able to see it at localhost/styles/style.css , so in my cgi script I referenced it as:

my $stylesheet = "/styles/style.css"; start_html(-style=>{'src'=>$stylesheet}), ....

Hope this is useful to someone else.

(The answer that helped me was found here: http://forums.devnetwork.net/viewtopic.php?f=1&t=113842 )

如果您“能够加载/styles/archiveRequest.css”,则也可以将“ /styles/archiveRequest.css”用作href。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM