2017-11-06 7 views
1

私は学校プロジェクト用のウェブサイトを作成しようとしています。ただし、navbar要素の位置がずれています。 navbar要素はバンド内にあるはずですが、バンドの半分をポップします。HTML Navbar:整列していない要素

a { 
 
    background-color: #666; 
 
    float: center; 
 
    display: inline; 
 
    padding-left: 50px; 
 
    padding-right: 50px; 
 
    padding-top: 15px; 
 
    padding-bottom: 15px; 
 
    margin: 0px; 
 
    overflow: hidden; 
 
    font-family: Arial; 
 
    text-align: center; 
 
} 
 

 
nav { 
 
    background-color: #666; 
 
    color: white; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    height: 40px; 
 
    margin-right: 40px; 
 
    margin-top: 0px; 
 
} 
 

 
a:hover { 
 
    color: #22A; 
 
} 
 

 
p { 
 
    text-align: center; 
 
}
<div class="navbar"> 
 
    <strong> 
 
    <p class="nav"> 
 
    <nav> 
 
    \t <a class="first-a-nav">Home</a> 
 
    \t <a class="first-a-nav">All Models</a> 
 
    \t <a class="first-a-nav">1 to 7 Series</a> 
 
    \t <a class="first-a-nav">X series</a> 
 
    \t <a class="first-a-nav">M series</a> 
 
    \t <a class="first-a-nav">BMW i</a> 
 
    </nav> 
 
    </p> 
 
    </strong> 
 
</div>

CSS部分がうまくoverflow: hidden作品他に、任意の短縮を図ることができませんでした。

要約すると:私のNabarは完全にを台無しにしました。それを元に戻すのを助けてください。

+1

[マークアップ検証ツール](https://validator.nu)と[CSS検証ツール](https://jigsaw.w3.org/css-validator/)から始めます。両方にマシン検出可能なエラーがあります。 – Quentin

答えて

0

インラインを使用する代わりに、インラインブロックを使用してみてください。

a { 
 
    background-color: #666; 
 
    float: center; 
 
    display: inline-block; 
 
    padding-left: 50px; 
 
    padding-right: 50px; 
 
    padding-top: 15px; 
 
    padding-bottom: 15px; 
 
    margin: 0px; 
 
    overflow: hidden; 
 
    font-family: Arial; 
 
    text-align: center; 
 
} 
 

 
nav { 
 
    background-color: #666; 
 
    color: white; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    height: 40px; 
 
    margin-right: 40px; 
 
    margin-top: 0px; 
 
} 
 

 
a:hover { 
 
    color: #22A; 
 
} 
 

 
p { 
 
    text-align: center; 
 
}
<div class="navbar"> 
 
    <strong> 
 
    <p class="nav"> 
 
    <nav> 
 
    \t <a class="first-a-nav">Home</a> 
 
    \t <a class="first-a-nav">All Models</a> 
 
    \t <a class="first-a-nav">1 to 7 Series</a> 
 
    \t <a class="first-a-nav">X series</a> 
 
    \t <a class="first-a-nav">M series</a> 
 
    \t <a class="first-a-nav">BMW i</a> 
 
    </nav> 
 
    </p> 
 
    </strong> 
 
</div>

0

あなたはこれを好きにしたいです。

a { 
 
    background-color: #666; 
 
    display: inline; 
 
    padding: 11px 77px; 
 
    font-family: Arial; 
 
} 
 

 
nav { 
 
    display: inline; 
 
    background-color: #666; 
 
    color: white; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    height: 40px; 
 
    margin-right: 40px; 
 
    margin-top: 0px; 
 
} 
 

 
a:hover { 
 
    color: #22A; 
 
} 
 

 
p { 
 
    text-align: center; 
 
}
<div class="navbar"> 
 
    <strong> 
 
    <p class="nav"> 
 
    <nav> 
 
    \t <a class="first-a-nav">Home</a> 
 
    \t <a class="first-a-nav">All Models</a> 
 
    \t <a class="first-a-nav">1 to 7 Series</a> 
 
    \t <a class="first-a-nav">X series</a> 
 
    \t <a class="first-a-nav">M series</a> 
 
    \t <a class="first-a-nav">BMW i</a> 
 
    </nav> 
 
    </p> 
 
    </strong> 
 
</div>

+0

テキストは左端にありますが、中央に置く必要があります。 –

+0

@Darsh Kはいテキストは一度中央揃えのみチェックします。 –

+0

@Dassh Kあなたはどの要素について話しています。もしあなたが 'margin:0 auto;'を特定のdivに適用するのでなければ、それはうまくいくでしょう。 –

0

さて、その非常にシンプル。 を削除します。 background-color: #666;をcssクラスからnav

+0

私はそれを試してみましたが、各リンクの間に白い隙間があります。 –

+0

はい、そのように見えます。メニューにはバックグラウンドがあり、スペースはバックグラウンドカラーで削除してください。#666; 'from' a ' – dean

関連する問題