0

我创建了一个新设计,其中包含一个导航元素和一个列表作为导航栏的基础,以尽可能地符合语义。我使用 CSS 对其进行样式设置,使其成为导航链接的水平列表。它被封装在一个 nav 元素中,并且被设计为具有黑色背景并与页面顶部齐平并扩展浏览器窗口的宽度。

我已经在许多浏览器中查看了该站点,并且列表是水平的并且按预期显示 - 即使在 IE9 中也是如此。但是,在 IE8 或更低版本中,它是页面左上角的垂直列表,并且根本没有 nav 元素的样式。我正在使用 HTML5 文档类型,因此 IE8 应该处于标准模式。

这是我要设置样式的 HTML。

<header>
    <nav>
        <ol>
        <li class="first"><a href="/#menu">Menu</a></li>
        <li><a href="/#locations”&gt;Location</a></li>
        <li><a href="/#about”&gt;About</a></li>
        <li><a href="/book.html”&gt;Book Us</a></li>
        <li class="telephone">☎ 555 555 5555</li>
        </ol>
    </nav>
    <img class="logo" src="/images/logo.png" style="vertical-align: middle;">
</header>

这是我正在使用的 CSS。

nav {
    font-size: 1.2em;
    font-weight: bold;
    text-shadow: 0 2px 6px #6e3000;
    vertical-align: middle;
    background-color: black;
    background: -webkit-gradient(linear,left top,left bottom,from(#333),to(#111));
    background: -moz-linear-gradient(top,#333,#111);
    width: 100%;
    border-color: rgb(216, 35, 42); /* red */
    border-bottom-style: ridge;
    border-bottom-width: medium;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

nav ol {
    padding-left: 5%;
    padding-right: 5%;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    list-style-type: none;
}

nav ol li {
    color: rgb(251, 243, 161); /* orange */
    display: inline;
    white-space: nowrap;
    margin: 1em;
    text-align: left;
}

nav ol li.right {
    float: right;
    text-align: right;
}

nav ol li a {
    color: rgb(251, 243, 161); /* orange */
    text-shadow: 0 1px 2px #000;
    text-decoration: none;
    display: inline;
}

nav ol li a:hover {
    /* background-color: rgb(175,30,30); */
    text-decoration: underline;
}

nav li.telephone {
    color: rgb(251, 243, 161); /* yellow */
    text-shadow: 0 1px 2px #000;
}

最后,这是我正在使用的 CSS 重置。它有一个用于旧浏览器的 HTML5 显示角色重置部分。

/* CSS Reset http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
4

2 回答 2

3

IE 8 不知道该nav元素。

所以你需要添加它。

head在您的文档部分添加以下代码(我认为在样式表之前):

<script>
  document.createElement('nav');
</script>

当我必须在页面上使用 HTML5 元素时(记住 HTML5 仍然有很长的路要走),我总是使用以下代码:

<script>
  document.createElement('header');
  document.createElement('nav');
  document.createElement('section');
  document.createElement('article');
  document.createElement('aside');
  document.createElement('footer');
  document.createElement('time');
</script>
于 2011-11-15T20:18:59.177 回答
0

它不是样式,因为 9 版之前的 IE 不支持 HTML5 标签,例如nav, 并且不支持未知标签。您可以使用HTML5 shiv解决它。如果你使用了Modernizr库,它内置了 shiv。

于 2011-11-15T20:26:07.863 回答