css - 如何让有序列表在 IE8 及以下版本中显示为水平导航栏?

标签 css html internet-explorer-8 nav

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

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

这是我要设置样式的 HTML。

<header>
    <nav>
        <ol>
        <li class="first"><a href="/#menu">Menu</a></li>
        <li><a href="/#locations”>Location</a></li>
        <li><a href="/#about”>About</a></li>
        <li><a href="/book.html”>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 Reset。它有一个适用于旧版浏览器的 HTML5 显示 Angular 色重置部分。

/* 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;
}

最佳答案

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>

关于css - 如何让有序列表在 IE8 及以下版本中显示为水平导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8142565/

相关文章:

javascript - css3-mediaqueries.js -> 如何从谷歌代码中包含?

internet-explorer - Twitter Bootstrap 下拉菜单在 Internet Explorer 中的样式不正确(根据文档中的示例)

jQuery设置attr IE8错误

javascript - 为什么 getBoundingClientRect 在 IE8 中很慢?

html - 平面设计师应该如何学习网页设计?

html - 如何将div内容设置到其父div的底部?

html - 在桌面上设置图像大小,但在使用移动设备时调整大小

html - 使用 css 的圆 div 内的细箭头

html - 文本颜色格式不起作用

javascript - 管理旋转元素上的拖动