cgi程序是可以直接通过BOA服务器运行的,如192.168.1.100/test.cgi。
原c代码中通过 printf("<link href=\"/c1.css\" rel=\"stylesheet\" type=\"text/css\">");将CSS样式文件引入cgi程序,但并没有在编译时将css中的内容像预编译一样写进来,后期在开发板上还是应当将css文件拷入同级目录等,从而使得cgi程序引用。
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Content-type:text/html\r\n\r\n");
printf("<html>");
printf("<head>");
printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
printf("<title>CSS实现折叠菜单</title>");
printf("<link href=\"/c1.css\" rel=\"stylesheet\" type=\"text/css\">");
printf("</head><body>");
printf("<ul id=\"abc\">");
printf("<li><a href=\"#\" >");
printf("<h1>烈火站长网2</h1>");
printf("<span>LIEHUO.NET为您提供站长教程、网页设计、源码资源等。</span></a></li>");
printf("<li><a href=\"#\" >");
printf("<h1>站长工具</h1>");
printf("<span>站长所需要的各类工具特应有尽有!</span></a></li>");
printf("<li><a href=\"#\" >");
printf("<h1>烈火论坛</h1>");
printf("<span>菜鸟级IT技术交流社区!</span></a></li>");
printf("<li class=\"end\"><a href=\"#\">");
printf("<h1>这是折叠标签</h1>");
printf("<span>这里是内容</span></a></li>");
printf("</body>");
return 0;
}
在虚拟机上通过arm-linux-gcc -static test.c -o test.cgi 编译为cgi程序拷入开发板
c1.css文件内容如下,这个文件跟test.cgi拷入开发板同一级目录中:
#abc { margin:0px;padding:0px;}
#abc h1{margin:0px; color:blue; font-size:14px;}
#abc li { list-style:none; display:block; width:178px; border:1px solid black; border-bottom-width:0px;}
#abc li.end{border-bottom-width:1px;}
#abc li a{ display:block; text-decoration:none; width:158px; padding:10px;}
#abc li a span{ display:none; color:#333; font-size:12px; padding:10px 0 0 0;}
#abc li a:hover{ background:red;}
#abc li a:hover span{ display:block; cursor: hand;}
/*重点就是对 #abc li a span区域的display属性的定义,平时不显露,在鼠标放上去(:hover)时显示就搞定了*/
运行结果如下:
原完整的HTML代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS实现鼠标触发展开折叠的精美菜单 - LIEHUO.NET</title>
<style type="text/css">
#abc { margin:0px;padding:0px;}
#abc h1{margin:0px; color:blue; font-size:14px;}
#abc li { list-style:none; display:block; width:178px; border:1px solid black; border-bottom-width:0px;}
#abc li.end{border-bottom-width:1px;}
#abc li a{ display:block; text-decoration:none; width:158px; padding:10px;}
#abc li a span{ display:none; color:#333; font-size:12px; padding:10px 0 0 0;}
#abc li a:hover{ background:red;}
#abc li a:hover span{ display:block; cursor: hand;}
/*重点就是对 #abc li a span区域的display属性的定义,平时不显露,在鼠标放上去(:hover)时显示就搞定了*/
</style>
</head>
<body>
<ul id="abc">
<li><a href="#" >
<h1>烈火站长网2</h1>
<span>LIEHUO.NET为您提供站长教程、网页设计、源码资源等。</span></a></li>
<li><a href="#" >
<h1>站长工具</h1>
<span>站长所需要的各类工具特应有尽有!</span></a></li>
<li><a href="#" >
<h1>烈火论坛</h1>
<span>菜鸟级IT技术交流社区!</span></a></li>
<li class="end"><a href="#">
<h1>这是折叠标签</h1>
<span>这里是内容</span></a></li>
</body>