此导航栏的输出在不同浏览器中有所不同,为什么会这样做?

时间:2014-09-11 07:25:53

标签: html css navigation

我还在学习HTML和CSS,现在我正在练习导航栏。此代码显示Mozilla和Chrome的不同填充,为什么这样做?事实上,我无法弄清楚为什么真的很烦人。我要在这里分享代码。

<!doctype html>
<html>
    <head>
        <title>Practice</title>

        <style>

    /* ====== RESET CODE ======= */  


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

    body {
            font-family: arial;
    }

         #top {
                width:100%;
                height:40px;
                background-color:#555;
         }

         .container {
                        margin:0 auto;
                        padding:0px;
                        width: 1000px;

         }

         #nav ul li {
                     float:left;
                     display:block;
                     margin:0px;
         }

         #search-bar {
                    float:right;
                    border: 1px solid;
                    width:315px;
                    position: relative;
                    top:5px;
         }

         .search {
                    width: 100%;
                    padding:2px;
         }

         a {
            padding: 18px 12px;
            color:#fff;
            text-decoration:none;
            margin:0px;
            position: relative;
            top:10px;
         }

         a:hover {
             background-color:#777;
             padding:11px 12px;
         }

        </style>
    </head>

    <body>
        <div id="top">
            <div class="container">
             <div id="nav">
                <ul>
                    <li><a href="#">Link</a></li>
                    <li><a href="#">Link Jupiter</a></li>
                    <li><a href="#">Link Venus</a></li>
                    <li><a href="#">Link Mars</a></li>
                    <li><a href="#">Link Neptune</a></li>
                    <li><a href="#">Link</a></li>
                    <li><a href="#">Link</a></li>
                    <li><a href="#">Link</a></li>
                </ul>
            </div>
                <div id="search-bar">
                    <input class="search" type="text" placeholder="search"/>
                </div>
            </div>
        </div>
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

所有浏览器都拥有自己的默认css。您尝试在RESET CODE中重置该默认css,但我认为您缺少一些元素。最好试试这个重置代码:

* {
    margin: 0;
    padding: 0;
    font-size: 12px;
    line-height: 1;
    zoom: 1;
    font: inherit;
    vertical-align: baseline;
}

答案 1 :(得分:-1)

使用导航栏进行导航: - http://getbootstrap.com/examples/navbar/

您可以从http://getbootstrap.com/

下载引导程序

使用bootstrap时非常容易