2017-08-31 13 views
1

私はウェブデベロッパーにとって非常に新しく、これは私が構築している最初のウェブサイトです。ナビゲーションバーはコンテナと同じではありません

私はナビゲーションバーでしばらく時間を費やしましたが、バーの幅がコンテナの最後に届くようにはできません。私は、私が抱えている問題を示すための写真を含んでいます。

1写真とナビゲーションバーは両方ともコンテナ内にありますが、私は両方の写真が並んでいるようにしたいと思います。

HTML & CSS:

<html> 
 
     <body> 
 
     \t \t <div class="header"> 
 
     \t \t \t \t <div class="container"> 
 
     \t \t \t \t \t <div class="logo"></div> 
 
     \t \t \t \t \t <div id="nav"> 
 
     \t \t \t \t \t \t <ul> 
 
     \t \t \t \t \t \t \t <li><a class="active" href="#index">Home</a></li> 
 
     \t \t \t \t \t \t \t <li><a href="#news">News</a></li> 
 
     \t \t \t \t \t \t \t <li><a href="#music">Music</a></li> 
 
     \t \t \t \t \t \t \t <li><a href="#about">About Us</a></li> 
 
     \t \t \t \t \t \t \t <li><a href="#contact">Contact Us</a></li> 
 
     \t \t \t \t \t \t </ul> 
 
     \t \t \t \t \t </div> 
 
     \t \t \t \t \t <div class="cover"></div> 
 
     
 
     \t \t \t \t </div> 
 
     
 
     
 
     \t \t </div> 
 
     \t <!-- Latest compiled and minified JavaScript --> 
 
     \t <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 
      
 
      <style type="text/css"> 
 
      
 
      body { 
 
     \t background-color: #505290 !important; 
 
     } 
 
     
 
     .header { 
 
     \t background-image: url(nlbg.jpg); 
 
     \t background-size: cover; 
 
     \t background-position: center center; 
 
     \t height: 10em; 
 
     \t width: 100%; 
 
     
 
     } 
 
     
 
     .logo { 
 
     \t content: url(nnlogo.png); 
 
     \t height: 120px; 
 
     } 
 
     
 
     #nav ul { 
 
      list-style-type: none; 
 
      background-color: #333; 
 
      text-align: center; 
 
      padding: 0; 
 
      margin: 1.4em; 
 
     } 
 
     
 
     #nav li { 
 
      font-family: arial, sans-serif; 
 
      font-size: 1.5em; 
 
      line-height: 40px; 
 
      height: 40px; 
 
      display: inline-block; 
 
      width: 19%; 
 
     } 
 
     
 
     #nav a{ 
 
      display: block; 
 
      color: white; 
 
     } 
 
     
 
     #nav a:hover { 
 
      background-color: #111; 
 
     } 
 
     
 
     #nav a.active { 
 
      background-color: #black; 
 
      color: #505290; 
 
     } 
 
     
 
     .cover { 
 
      content: url(cover.jpg); 
 
     
 
     } 
 
      
 
      </style> 
 
     </body> 
 
    </html>

+0

マージン0 ul。 –

答えて

0

あなたのnavbarにはtop/left/bottom/rightのマージンのがあります。 top/bottomのマージンを維持する場合は、margin:1.4em 0;に設定してleft/rightのマージンをゼロにします。

body { 
 
    background-color: #505290 !important; 
 
} 
 

 
.header { 
 
    background-image: url(nlbg.jpg); 
 
    background-size: cover; 
 
    background-position: center center; 
 
    height: 10em; 
 
    width: 100%; 
 

 
} 
 

 
.logo { 
 
    content: url(nnlogo.png); 
 
    height: 120px; 
 
} 
 

 
#nav ul { 
 
    list-style-type: none; 
 
    background-color: #333; 
 
    text-align: center; 
 
    padding: 0; 
 
    margin: 1.4em 0; 
 
} 
 

 
#nav li { 
 
    font-family: arial, sans-serif; 
 
    font-size: 1.5em; 
 
    line-height: 40px; 
 
    height: 40px; 
 
    display: inline-block; 
 
    width: 19%; 
 
} 
 

 
#nav a{ 
 
    display: block; 
 
    color: white; 
 
} 
 

 
#nav a:hover { 
 
    background-color: #111; 
 
} 
 

 
#nav a.active { 
 
    background-color: #black; 
 
    color: #505290; 
 
} 
 

 
.cover { 
 
    content: url(cover.jpg); 
 

 
}
<body> 
 
     <div class="header"> 
 
       <div class="container"> 
 
        <div class="logo"></div> 
 
        <div id="nav"> 
 
         <ul> 
 
          <li><a class="active" href="#index">Home</a></li> 
 
          <li><a href="#news">News</a></li> 
 
          <li><a href="#music">Music</a></li> 
 
          <li><a href="#about">About Us</a></li> 
 
          <li><a href="#contact">Contact Us</a></li> 
 
         </ul> 
 
        </div> 
 
        <div class="cover"></div> 
 

 
       </div> 
 

 

 
     </div> 
 
</body>

+0

母は私はこれがあったかシンプルで驚いては、もはや私は「より過ごし笑だけでなく、この問題についてのヘルプは 感謝を認めるのが好きdは! – ThatWain

+0

あなたは大歓迎です!デフォルトでは、 '順序付けられていないリスト'にはブラウザによって 'margin 'が適用されることに注意してください。ナビゲーションに使うときは、そのデフォルトマージンを取り消したり上書きしたりしてください。 – APAD1

-1

ul上のマージンを調整してみてください:

body { 
 
    background-color: #505290 !important; 
 
} 
 

 
.header { 
 
    background-image: url(nlbg.jpg); 
 
    background-size: cover; 
 
    background-position: center center; 
 
    height: 10em; 
 
    width: 100%; 
 
} 
 

 
.logo { 
 
    content: url(nnlogo.png); 
 
    height: 120px; 
 
} 
 

 
#nav ul { 
 
    list-style-type: none; 
 
    background-color: #333; 
 
    text-align: center; 
 
    padding: 0; 
 
    /*margin: 1.4em;*/ 
 
} 
 

 
#nav li { 
 
    font-family: arial, sans-serif; 
 
    font-size: 1.5em; 
 
    line-height: 40px; 
 
    height: 40px; 
 
    display: inline-block; 
 
    width: 19%; 
 
} 
 

 
#nav a { 
 
    display: block; 
 
    color: white; 
 
} 
 

 
#nav a:hover { 
 
    background-color: #111; 
 
} 
 

 
#nav a.active { 
 
    background-color: black; 
 
    color: #505290; 
 
} 
 

 
.cover { 
 
    content: url(https://placehold.it/800x800); 
 
} 
 

 
ul { 
 
    margin: 0; 
 
}
<div class="header"> 
 
    <div class="container"> 
 
    <div class="logo"></div> 
 
    <div id="nav"> 
 
     <ul> 
 
     <li><a class="active" href="#index">Home</a></li> 
 
     <li><a href="#news">News</a></li> 
 
     <li><a href="#music">Music</a></li> 
 
     <li><a href="#about">About Us</a></li> 
 
     <li><a href="#contact">Contact Us</a></li> 
 
     </ul> 
 
    </div> 
 
    <div class="cover"></div> 
 

 
    </div> 
 

 

 
</div>

+0

余白を削除するだけで、必要以上に変更が加えられます。 margin-leftを0に設定し、残りの部分を残しておきます。 – Daniel

+0

十分@Danielフェアが、答えは、問題が何だったかOPにそれはかなり明白になります、と彼が望んでいるとして、彼はを微調整することができます... – sol

-1

1.4emのご#nav ulマージンがあなたのNAVのULの左側にマージンを加えています。その上で左に0を設定します。

関連する問題