完全用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=”<a href=”http://www.knowsky.com/article.asp?typeid=36“>javascript</a>: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>

随机文章:

1、wp中文固定链接slug自动翻译成英文或汉语拼音
https://www.onexin.net/wp-chinese-permalink-slug-automatically-translated-into-english-or-pinyin/

2、最新网站首页被K的补救方法
https://www.onexin.net/latest-home-remedy-of-k/

3、CentOS 5.6 发行注记
https://www.onexin.net/centos-5-6-release-notes/

4、你知道这些css网页设计技巧吗
https://www.onexin.net/you-know-that-these-techniques-do-css-web-design/

5、Magento升级1.6.0.0 alpha1(笔记)
https://www.onexin.net/magento-upgrade-1-6-0-0-alpha1-notes/

转载请注明出处:https://www.onexin.net/completely-with-css-in-the-bilingual-navigation-menu/

Leave a Reply

Your email address will not be published. Required fields are marked *