我应该使用什么HTML5元素来构建前端菜单?

时间:2016-01-13 19:07:32

标签: css3

我知道HTML5提供了菜单元素,但我不记得它们是什么。

对于具有可读性的HTML5元素是否有很好的参考?

1 个答案:

答案 0 :(得分:2)

我认为您的意思是HTML,那就是<nav>元素,通常与<ul><li>结合使用。喜欢:

&#13;
&#13;
body {
  background-color: #EBE8E4;
  color: #222;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
  font-size: 15px;
}
nav {
  background-color: #fff;
  border: 1px solid #dedede;
  border-radius: 4px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
  color: #888;
  display: block;
  margin: 8px 22px 8px 22px;
  overflow: hidden;
  width: 90%;
}
nav ul {
  margin: 0;
  padding: 0;
}
nav ul li {
  display: inline-block;
  list-style-type: none;
  transition: all 0.2s;
}
nav > ul > li > a > .caret,
nav > ul > li > ul > li > a > .caret {
  border-top: 4px solid #aaa;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  content: "";
  display: inline-block;
  height: 0;
  width: 0;
  vertical-align: middle;
  transition: color 0.1s linear;
}
nav > ul > li > ul > li > a > .caret {
  border-bottom: 4px solid transparent;
  border-top: 4px solid transparent;
  border-right: 4px solid transparent;
  border-left: 4px solid #f2f2f2;
  margin: 0 0 0 8px;
}
nav > ul > li > a {
  color: #aaa;
  display: block;
  line-height: 56px;
  padding: 0 24px;
  text-decoration: none;
}
nav > ul > li:hover {
  background-color: rgb(40, 44, 47);
}
nav > ul > li:hover > a {
  color: rgb(255, 255, 255);
}
nav > ul > li:hover > a > .caret {
  border-top-color: rgb(255, 255, 255);
}
nav > ul > li > div ul > li:hover > a > .caret {
  border-left-color: rgb(255, 255, 255);
}
nav > ul > li > ul,
nav > ul > li > ul > li > ul {
  background-color: rgb(40, 44, 47);
  border-top: 0;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
  display: none;
  margin: 0;
  opacity: 0;
  position: absolute;
  width: 165px;
  visibility: hidden;
  transition: opacity 0.2s;
}
nav > ul > li > ul > li > ul {
  background-color: rgb(40, 44, 47);
  border-radius: 0 4px 4px 4px;
  box-shadow: inset 2px 0 5px rgba(0, 0, 0, .15);
  margin-top: -42px;
  right: -165px;
}
nav > ul > li:hover > ul,
nav > ul > li > ul > li:hover > ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
nav > ul > li > ul > li,
nav > ul > li > ul > li > ul > li {
  display: block;
  position: relative;
}
nav > ul > li > ul > li > a,
nav > ul > li > ul > li > ul > li > a {
  color: #fff;
  display: block;
  padding: 12px 24px;
  text-decoration: none;
}
nav > ul > li > ul > li:hover > a {
  background-color: rgba(255, 255, 255, 0.1);
}
&#13;
<nav>
  <ul>
    <li><a>Home</a>
    </li>
    <li><a>Menu 1<span class="caret"></span></a>
      <ul>
        <li><a>Sub Menu 1-1</a>
        </li>
        <li><a>Sub Menu 1-2</a>
        </li>
      </ul>
    </li>
  </ul>
</nav>
&#13;
&#13;
&#13;