这个导航栏在不同浏览器中的输出是不同的,为什么要这样做



我还在学习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>

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

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

对导航栏使用引导程序:-http://getbootstrap.com/examples/navbar/

您可以从以下位置下载引导程序:http://getbootstrap.com/

使用引导时非常容易

相关内容

最新更新