美文网首页
精通CSS高级Web标准解决方案读书笔记-06对列表和创建导航条

精通CSS高级Web标准解决方案读书笔记-06对列表和创建导航条

作者: 前端大魔王 | 来源:发表于2018-03-03 17:12 被阅读0次

1.创建基本的垂直导航条

<style type="text/css">
body {
  font-family: "Myriad Pro", Frutiger, "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
  font-size: 1.4em;
}
ul.nav {
  margin: 0;
  padding: 0;
  width: 8em;
  list-style-type: none;
    float: left;
    background-color: #8BD400;
    border: 1px solid #486B02;
    border-bottom: none;
}
ul.nav li {
  display: inline: /* :KLUDGE: Removes large gaps in IE/Win */
}
ul.nav a {
  display: block;
    color: #2B3F00;
  text-decoration: none;
    border-top: 1px solid #E4FFD3;
    border-bottom: 1px solid #486B02;
  background: url(img/arrow.gif) no-repeat 5% 50%;
    padding: 0.3em 1em;
}

/*ul .last a {
    border-bottom: 0;
}*/

ul.nav a:hover,
ul.nav a:focus,
ul.nav .selected a {
    color: #E4FFD3;
    background-color: #6DA203;
}
</style>
</head>
<body>
<ul class="nav">
<li class="selected"><a href="home.htm">Home</a></li>
<li><a href="about.htm">About</a></li>
<li><a href="services.htm">Our Services</a></li>
<li><a href="work.htm">Our Work</a></li>
<li><a href="news.htm">News</a></li>
<li class="last"><a href="contact.htm">Contact</a></li>
</ul>
</body>

2.创建简单的水平导航条

<style type="text/css">

body {
  font-family: "Myriad Pro", Frutiger, "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
  font-size: 1.4em;
    margin-top: 4em;
}

ol.pagination {
  margin: 0;
  padding: 0;
  list-style-type: none;
}

ol.pagination li {
    float: left;
    margin-right: 0.6em;
}
ol.pagination a,
ol.pagination li.selected {
    display: block;
    padding: 0.2em 0.5em;
    border: 1px solid #ccc;
    text-decoration: none;
}
ol.pagination a[rel="prev"],
ol.pagination a[rel="next"] {
    border: none;
}
ol.pagination a[rel="prev"]:before {
    content: "\00AB";
    padding-right: 0.5em;
}
ol.pagination a[rel="next"]:after {
    content: "\00BB";
    padding-left: 0.5em;
}
ol.pagination a:hover,
ol.pagination a:focus,
ol.pagination li.selected {
    background-color: blue;
    color: white;
}
</style>
</head>
<body>
<ol class="pagination">
<li><a href="search.htm?page=1" rel="prev">Prev</a></li>
<li><a href="search.htm?page=1">1</a></li>
<li class="selected">2</li>
<li><a href="search.htm?page=3">3</a></li>
<li><a href="search.htm?page=4">4</a></li>
<li><a href="search.htm?page=5">5</a></li>
<li><a href="search.htm?page=3" rel="next">Next</a></li>
</ol>
</body>

为了让列表水平排列而不是垂直,可以把display属性设置为inline,但是对于复杂的水平列表样式,如果浮动列表项,然后用外边距分开则更灵活。

3.滑动门标签页导航。

在li上与其内的a上分别应用大背景可以实现。滑动门技术详见读书笔记的04章。

4. 下拉菜单

将子导航嵌在无序列表中。li应用hover

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Horizontal Nav</title>
<style type="text/css">
body {
  font-family: "Myriad Pro", Frutiger, "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
  font-size: 1.4em;
    margin-top: 4em;
}

ul.nav, ul.nav ul {
  margin: 0;
  padding: 0;
  list-style-type: none;
    float: left;
    border: 1px solid #486B02;
    background-color: #8BD400;
}

ul.nav li {
    float: left;
    width: 8em;
}

ul.nav li ul {
    position: absolute;
    width: 8em;
    left: -999em;
    margin-left: -1px;
}

.nav li:hover ul {
    left: auto;
}

ul.nav a {
    display: block;
    color: #2B3F00;
  text-decoration: none;
    padding: 0.3em 1em;
  border-right: 1px solid #486B02;
    border-left: 1px solid #E4FFD3;*/
}

ul.nav li li a {
    border-top: 1px solid #E4FFD3;
    border-bottom: 1px solid #486B02;   
    border-left: 0;
    border-right: 0;
}

ul.nav li:last-child a {
    border-right: 0;
    border-bottom: 0;
}

ul a:hover,
ul a:focus {
    color: #E4FFD3;
    background-color: #6DA203;
}
</style>
</head>

<body>

<ul class="nav">
<li><a href="/home/">Home</a></li>
<li><a href="/products/">Products</a>
<ul>
<li><a href="/products/silverback/">Silverback</a></li>
<li><a href="/products/fontdeck/">Font Deck</a></li>
</ul>
</li>

<li><a href="/services/">Services</a>
<ul>
<li><a href="/services/design/">Design</a></li>
<li><a href="/services/development/">Development</a></li>
<li><a href="/services/consultancy/">Consultancy</a></li>
</ul>
</li>
<li><a href="/contact/">Contact Us</a></li>
</ul>

</body>

在ie老搬中不支持在非锚元素上使用:hover,可以使用几行javascript或.htc行为文件解决。

5. 远距离翻转

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Remote Rollovers</title>


<style type="text/css">
<!--

body {
  font: 62.5%/1.6 "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
}  

.remote {
  width: 333px;
  height: 500px;
  position: relative;
}

.remote ul {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 1.8em;
}

.remote a {
  text-decoration: none;
  color: #039;
}

.remote a .hotspot {
  width: 50px;
  height: 60px;
  position: absolute;
    background-image: url(img/shim.gif);
}

.remote a .link {
  position: absolute;
  display: block;
  width: 10em;
  right: -11em;
    cursor: pointer;
}

.remote a:hover .hotspot,
.remote a:focus .hotspot {
  border: 1px solid #fff;
}

.remote a:hover .link,
.remote a:focus .link {
  color: #0066FF;
}

.remote .rich a .hotspot {
  top: 50px;
  left: 80px;
}

.remote .sophie a .hotspot {
  top: 90px;
  left: 200px;
}

.remote .cath a .hotspot {
  top: 140px;
  left: 55px;
  width: 60px;
  height: 80px;
}

.remote .james a .hotspot {
  top: 140px;
  left: 145px;
}

.remote .paul a .hotspot {
  top: 165px;
  left: 245px;
  width: 60px;
  height: 80px;
}


.remote .rich a .link {
  top: 0;
}

.remote .sophie a .link {
  top: 1.2em;
}

.remote .cath a .link {
  top: 2.4em;
}

.remote .james a .link {
  top: 3.6em;
}

.remote .paul a .link {
  top: 4.8em;
}


-->
</style>
</head>

<body>

<div class="remote">
<img src="img/nerdcore.jpg" width="333" height="500" alt="Rich, Sophie, Cath, James and Paul" />
<ul>

<li class="rich">
    <a href="http://www.clagnut.com/" title="Richard Rutter">
    <span class="hotspot"></span>
    <span class="link">» Richard Rutter</span>
    </a>
</li>

<li class="sophie">
    <a href="http://www.wellieswithwings.org/" title="Sophie Barrett">
    <span class="hotspot"></span>
    <span class="link">» Sophie Barrett</span>
    </a>
</li>

<li class="cath">
    <a href="http://www.electricelephant.com/" title="Cathy Jones">
    <span class="hotspot"></span>
    <span class="link">» Cathy Jones</span>
    </a>
</li>

<li class="james">
<a href="http://www.jeckecko.net/blog/" title="James Box">
    <span class="hotspot"></span>
    <span class="link">» James Box</span>
    </a>
</li>

<li class="paul">
    <a href="http://twitter.com/nicepaul" title="Paul Annett">
    <span class="hotspot"></span>
    <span class="link">» Paul Annett</span>
    </a>
</li>

</ul>
</div>

</body>

结果


总结

学习了简单的导航条,
水平导航条,
滑动门导航,
下拉菜单,
翻转。

相关文章

网友评论

      本文标题:精通CSS高级Web标准解决方案读书笔记-06对列表和创建导航条

      本文链接:https://www.haomeiwen.com/subject/jpsosttx.html