在以往的一些教程中,都喜欢把背景图切成一宽一窄两部分进行拼接,其实一张图就足矣。
在这里,我们只用了跟两个标签,样式可以定义三种状态,可以说是最简单的一种方式了。
!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"headmeta http-equiv="Content-Type" content="text/html; charset=utf-8" /title无标题文档/titlestylebody {font-size:12px;}.nav {margin:0 auto; text-align:center; font-weight:bold; border-bottom:3px solid #579cc6;}.nav a {display:inline-block; margin:0 3px; height:25px; background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) left bottom no-repeat; padding-left:15px; color:#666; text-decoration:none; cursor:pointer;}.nav a span {display:inline-block; height:25px; line-height:25px; background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) right bottom no-repeat; padding-right:15px;}.nav a:hover {background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) left top no-repeat; color:#FFF;}.nav a:hover span {background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) right top no-repeat;}.nav a.set {background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) left top no-repeat; color:#FFF; }.nav a.set span {background:url(http://www.webjx.comhttp://img.warting.com/allimg/2010/c0502/12HNc2D4D0-26322.jpg) right top no-repeat;}/style/headbodydiv class="nav"a class="set" href="#"span首页/span/aa href="#"span分类一/span/aa href="#"span分类分类/span/aa href="#"span还可以再长一点/span/aa href="#"span欢迎/span/aa href="#"span我的博客/span/a/div/body/html [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]