完全用CSS實現的中英文雙語導覽功能表

來源:互聯網
上載者:User
css|菜單

這是一個完全用CSS實現的中英文雙語導覽功能表,無指令碼和圖片,初始時,菜單語言是英文,當滑鼠移至上方在菜單上時,其變成中文,當然你也可以反過來做。

實現原理:

   XHTML

<ul id="nav">
<li><a class="bi" href="index.html">Home<span>首 頁</span></a></li>
</ul>

從上面代碼可以看出,中文放在 span 標籤裡,關鍵是需要在初始時,使其的屬性不可見。

   CSS

.bi{
position: relative;
z-index: 0;
}

.bi:hover{
z-index: 99;
}

.bi:hover span{
visibility: visible;
top: 0;
left: 0;
cursor: pointer;
}

.bi span{
position: absolute;
left: -999em;
visibility: hidden;
}

#nav li a,.bi:hover span{
line-height: 20px;
text-decoration: none;
background: #DDDDDD;
color: #666666;
display: block;
width: 80px;
text-align: center;
}

#nav li a:hover,.bi:hover span{
color: #FFFFFF;
background: #DC4E1B;
}

.bi:hover span{
padding-top: 2px;
}

連結的屬性是相對定位,那在此標籤裡的元素可將其作為參照點。 在 span 元素裡的中文因其設定了不可見,所以在初始狀態時,只能顯示英文。而當滑鼠移至上方在菜單上時,

span 元素裡的設定變為可見,Z軸為99 ,覆蓋在英文上面,從而實現了語言文字的轉換。缺點:因為中英文字的長度關係,不能實現自適應寬度,只能固定寬度。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="Keywords" content="bilingual menu,中英文雙語菜單" /><meta http-equiv="Description" content="完全用CSS實現的中英文雙語導覽功能表" /><meta content="all" name="robots" /><meta http-equiv="pragma" content="no-cache" /><meta name="author" content="forestgan" /><meta name="copyright" content="forestgan" /><title>完全用CSS實現的中英文雙語導覽功能表</title><style type="text/css">a{ color: #FFFF99; text-decoration: none;}a:hover{ color: #FFFFFF; text-decoration: underline;} #nav{ padding: 10px 10px 0; font-size: 12px; font-weight: bold; margin: 1em 0 0; list-style:none;}#nav li{ float: left; margin-right: 1px;}.bi{ position: relative; z-index: 0;}.bi:hover{ z-index: 99;}.bi:hover span{ visibility: visible; top: 0; left: 0; cursor: pointer;}.bi span{ position: absolute; left: -999em; visibility: hidden;}#nav li a,.bi:hover span{ line-height: 20px; text-decoration: none; background: #DDDDDD; color: #666666; display: block; width: 80px; text-align: center;}#nav li a:hover,.bi:hover span{ color: #FFFFFF; background: #DC4E1B;}.bi:hover span{ padding-top: 2px;}#navbar{ background: #DC4E1B; height: 8px; overflow: hidden; clear: both;}</style><link href="../css/main.css" rel="stylesheet" type="text/css" /></head><body><div id="top"> <ul id="nav"> <li><a class="bi" href="index.html">Home<span>首 頁</span></a></li> <li><a class="bi" href="about.html">About us<span>關於我們</span></a></li> <li><a class="bi" href="products.html">Products<span>產品展示</span></a></li> <li><a class="bi" href="services.html">Services<span>售後服務</span></a></li> <li><a class="bi" href="contact.html">Contact<span>聯絡我們</span></a></li> </ul> <div id="navbar"></div></div><div id="footer"> <address> Design by <a href="http://www.forest53.com">forestgan</a> 本示範採用<a href="http://www.creativecommons.cn/">創作共用授權</a>--署名和非商業用途。  <a href="javascript:history.back()">Back</a> </address></div><script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-152060-1";urchinTracker();</script><noscript>google-analytics</noscript><script src="http://www.forest53.com/stat/mystat.asp?siteid=1" type="text/javascript"></script><noscript>stat.</noscript></body></html><script language="Javascript"> var now = new Date(); document.write("<img src='http://counter.yesky.com/counter.shtml?CID=54197&AID=-1&refer="+escape(document.referrer)+"&rand="+ now.getTime() + "&cur="+escape(document.URL)+"' border='0' alt='' width='0' height='0'>"); </script> <noscript> <img src="http://counter.yesky.com/counter.shtml?CID=54197&AID=-1&refer=noscriptcounter&cur=noscriptcounter" border='0' width='0' height='0'/> </noscript>
 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.