當前位置:首頁 » 編程語言 » 網站c語言導航條生成器官網
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

網站c語言導航條生成器官網

發布時間: 2023-01-28 22:35:40

⑴ 怎樣用PHP來給網頁做導航欄

本文只需要讀者具備PHP、HTML的初步知識就可以基本讀懂了。 譯文:如大家所知PHP對於用資料庫驅動的網站(making database-driven sites)來講可謂功能強大,可是我們是否可以用它來做點其他事情呢?PHP給了我們所有我們期望的工具:for與while的循環結構、數學運算等等,還可以通過兩種方式來引用文件:直接引用或向伺服器提出申請。其實何止這些,讓我們來看一個如何用它來做導航條的例子:完整的原代碼:<!—— This "<?" is how you indicate the start of a block of PHP code, ——> <?PHP # and this "#" makes this a PHP comment. $full_path = getenv("REQUEST_URI"); $root = dirname($full_path);$page_file = basename($full_path);$page_num = substr($page_file, strrpos($page_file, "_") + 1, strpos($page_file, ".html") - (strrpos($page_file, "_") + 1)); $partial_path = substr($page_file, 0, strrpos($page_file, "_")); $prev_page_file = $partial_path . "_" . (string)($page_num-1) . ".html";$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".html"; $prev_exists = file_exists($prev_page_file);$next_exists = file_exists($next_page_file); if ($prev_exists) { print "<a href="$root/$prev_page_file">previous</a>";if ($next_exists) { print " | ";} if ($next_exists) { print "<a href="$root/$next_page_file">next</a>";} ?>//原程序完。 代碼分析:OK! 前面做了足夠的鋪墊工作,現在讓我們來看看如何來用PHP來完成這項工作: <!—— This "<?" is how you indicate the start of a block of PHP code, ——> <?PHP # and this "#" makes this a PHP comment. $full_path = getenv("REQUEST_URI"); $root = dirname($full_path);$page_file = basename($full_path); /* PHP函數getenv()用來取得環境變數的值,REQUEST_URI的值是緊跟在主機名後的部分URL,假如URL是, 那它的值就為/dinner/tuna_1.html. 現在我們將得到的那部分URL放在變數$full_path中,再用dirname()函數來從URL中抓取文件目錄,用basename()函數取得文件名,用上面的例子來講dirname()返回值:/dinner/;basename()返回:tuna_1.html.接下來的部分相對有些技巧,假如我們的文件名以story_x的格式命名,其中x代表頁碼,我們需要從中將我們使用的頁碼抽出來。當然文件名不一定只有一位數字的模式或只有一個下劃線,它可以是tuna_2.html,同樣它還可以叫做tuna_234.html甚至是candy_apple_3.html,而我們真正想要的就是位於最後一個「_」和「。html」之間的東東。可採用如下方法:*/ $page_num = substr($page_file, strrpos($page_file, "_") + 1, strpos($page_file, ".html") - (strrpos($page_file, "_") + 1));/* substr($string, $start,[$length] )函數給了我們字元串$string中從$start開始、長為$length或到末尾的字串(方括弧中的參數是可選項,如果省略$length,substr就會返回給我們從$start開始直到字元串末尾的字元串),正如每一個優秀的C程序員告訴你的那樣,代表字元串開始的位置開始的數字是「0」而不是「1」。 函數strrpos($string, $what)告訴我們字元串$what在變數$string中最後一次出現的位置,我們可以通過它找出文件名中最後一個下劃線的位置在哪,同理,接著的strpos($string, $what)告訴我們「。html」首次出現的位置。我們通過運用這三個函數取得在最後一個「_」和「。html」之間的數字(代碼中的strpos()+1代表越過「_」自己)。 剩下的部分很簡單,首先為上頁和下頁構造文件名:*/ $partial_path = substr($page_file, 0, strrpos($page_file, "_")); $prev_page_file = $partial_path . "_" . (string)($page_num-1) . ".html";$next_page_file = $partial_path . "_" . (string)($page_num+1) . ".html"; /*(string)($page_num+1)將數學運算$page_num+1的結果轉化為字元串類型,這樣就可以用來與其他字串最終連接成為我們需要的文件名。 */ /*現在檢查文件是否存在(這段代碼假設所有的文件都位於同樣的目錄下),並最終給出構成頁面導航欄的HTML代碼。>

⑵ 高手們!!!怎麼製作網站 的下拉式導航條

用CSS巧制微軟下拉式導航條
(作者:touch8 2002年02月20日 09:17)

去過微軟中國站點(http://www.microsoft.com/china)的朋友都會對它的下拉菜單式導航條感興趣,微軟的製作方法比較復雜,不是一般菜鳥能學會的,於是就有很多人想出各種辦法模擬製作,可是不是要用到很多層就是要用到腳本,感覺還是挺麻煩。我的做法可就簡單多了,而且效果不錯,看看本文抬頭的導航條,再和微軟站點的比較一下,怎麼樣?是不是幾乎一模一樣?你只要會點html和CSS的一些基本知識就能做到,具體的方法如下:

第一步:

為鏈接建立樣式,代碼如下:

a:visited{color:white}
a:link{color:white}
a:active{color:white}
a:hover{color:red }

說明:除了hover是紅色外,其他都是白色,和微軟一致。

第二步:

建立一個表格,以便放菜單內容,如建立一個3行1列的表格如下:

說明:表格參數均為0,即border="0" cellpadding="0" cellspacing="0" 這里為了解釋方便所以留了邊框。

第三步:

將菜單內容添入表格並加上鏈接,如下:

主頁
微軟中國
美國總部

第四步:

下面我們要建立樣式了,首先建立一個名為close的樣式,代碼如下:

.close{visibility:hidden;background:#6699ff;height:23px;
color:white;font:9pt;text-align:center}

說明:使用hidden屬性,說白了就是什麼也看不到了!

再來建立一個樣式名為open,代碼如下:

.open{visibility:visible;background:#6699ff;height:23px;
color:white;font:9pt;text-align:center}

說明:背景採用天藍色,字體為9pt,和微軟保持一致,使用visible屬性,即可見。

第五步:

既然樣式已經建好了,我們就來調用,代碼如下:

<table width="100" border="0" cellpadding="0" cellspacing="0"class=close>
<tr>
<td class=open><a href="#">主頁</a></td>
</tr>
<tr>
<td><a href="#">微軟中國</a></td>
</tr>
<tr>
<td><a href="#">美國總部</a></td>
</tr>
</table>

說明:整個表格採用close樣式,而「主頁」單元格採用open樣式,充分利用CSS優先權的規則,所產生的效果是只能看到「主頁」這個單元格。

第六步:

這是關鍵的一步,用行為調用樣式,代碼如下:

<table width="100" class=close onMouseOut="this.style.visibility='hidden'"
onMouseOver="this.style.visibility='visible '"
cellpadding="0" cellspacing="0" border="0" >
<tr>
<td class=open> <a href="#">主頁</a></td>
</tr>
<tr>
<td><a href="#">微軟中國</a></td>
</tr>
<tr>
<td><a href="#">美國總部</a></td>
</tr>
</table>

說明:當mouseover即滑鼠移上時,表格變為可見,而當onmouseout即滑鼠移開時,表格恢復不可見樣式。

最後一步:

一個下拉菜單已經做好了,現在建立一個1x8的表格,再把下拉菜單插到各個單元格裡面,最後把這個大的表格放到一個層里(這樣容易定位),大功告成!

為了方便你學習,下面是本菜單式導航條的全部代碼,你可以把代碼拷貝到記事本里,保存為一個txt文件,然後將這個文件的擴展名由.txt改為.htm,就可以直接用IE打開了。

<html>
<head>
<title>用CSS做下拉式菜單</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
body{margin-top:50}
.td{font:9pt;color:green}
a:visited{color:white}
a:link{color:white}
a:active{color:white}
a:hover{color:red }
..close{visibility:hidden;background:#6699ff;
height:23px;color:white;font:9pt;text-align:center}
..open{visibility:visible;background:#6699ff;
height:23px;color:white;font:9pt;text-align:center}
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000" >
<div id="Layer1" style="position:absolute;
left:4px; top:4px; width:1000px; height:108px;
z-index:1">
<table width="100%" border="0" align="center"
cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
a.style.height='23'" onMouseOver="this.style.
visibility='visible';
a.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=a class=open > <a href="#">主頁</a>
|</td>
</tr>
<tr >
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">微軟中國</a></td>
</tr>
<tr>
<td><a href="#">美國總部</a></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
b.style.height='23'" onMouseOver="this.style.
visibility='visible';
b.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=b class="open"><a href="#">活動與培訓</a>|</td>
</tr>
<tr >
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">在線講座</a></td>
</tr>
<tr>
<td ><a href="#">任證與培訓 </a></td>
</tr>
<tr>
<td ><a href="#">微軟出版社</a></td>
</tr>
<tr>
<td ></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
c.style.height='23'" onMouseOver="this.style.
visibility='visible';
c.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=c class=open><a href="#">定閱電子期刊
</a>|</td>
</tr>
<tr >
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">訂閱</a></td>
</tr>
<tr>
<td><a href="#">修改</a></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
d.style.height='23'" onMouseOver="this.style.
visibility='visible';
d.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=d class=open><a href="#">微軟中國</a>
|</td>
</tr>
<tr>
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">新聞</a></td>
</tr>
<tr>
<td><a href="#">動態傳真</a></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%"class=open cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td ><a href="#">微軟總部
</a> |</td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
e.style.height='23'" onMouseOver="this.style.
visibility='visible';
e.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=e class=open><a href="#">購買與許可
</a>|</td>
</tr>
<tr>
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">版權與許可</a></td>
</tr>
<tr>
<td><a href="#">購買指南</a></td>
</tr>
<tr>
<td><a href="#">我用正版</a></td>
</tr>
<tr>
<td><a href="#">商標指南</a></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=close onMouseOut="this.style.visibility='hidden' ;
f.style.height='23'" onMouseOver="this.style.
visibility='visible';
f.style.height='21'" cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td id=f class=open><a href="#">站點地圖</a>|</td>
</tr>
<tr>
<td bgcolor=white></td>
</tr>
<tr>
<td><a href="#">站點內幕</a></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td valign="top" width="12%">
<table width="100%" class=open cellpadding="0"
cellspacing="0" border="0" >
<tr>
<td ><a href="#">招賢納士 </a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div align="left"> </div>
</body>
</html>

⑶ 怎樣製作網站首頁導航條

非常簡單的,背景色,打幾個字,把鏈接一加就算是一個導航條了,復雜的多了去了