2012-03-29 7 views
0

私はコンテナからNavbarを分離しましたが、今は空きスペースがなくても、divマージンとパディングを設定しようとしましたが、負のマージンを使用するには、どんな助けも大歓迎です。コンテナとnavbarの間の奇妙な空間

HTML

<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Test</title> 
    <link href="body.css" rel="stylesheet" type="text/css"> 
    <link href="navbar1.css" rel="stylesheet" type="text/css"> 
    </head> 

    <body> 
     <div id="navbar"> 
     <ul> 
     <li>black</li> 
     <li>blue</li> 
     <li>green</li> 
     <li>yellow</li> 
     <li>haha</li> 
     <li>good</li> 
     </ul> 
    </div><!-- End of navbar --> 
    <div id="container"> 
    <div class="logo"> 
      <img src="" alt="sun" /> 
    </div><!-- End of logo --> 

    <div id="header1"> 
      <span>Hello World</span> 
    </div><!-- End of header --> 

    <div class="logo"> 
      <img src="" alt="sun" /> 
    </div><!-- End of logo --> 
    <div id="p1"> 
      <p> up </p> 
    </div><!-- End of p1 --> 
     </div><!-- End of container --> 
    </body> 
    </html> 

CSS

#navbar /* navbar container */ 
{ 
    background-color:#999; 
    border-bottom:solid 3px #333; 
    margin:0px; 
} 
#navbar ul /* unordered lists withinin navbar container */ 
{ 
    width:1000px; 
    text-align:center; 
    margin-top:0px; 
    margin-bottom:0px; 
    list-style:none; 
    margin-left:auto; 
    margin-right:auto; 
    padding:0px; 
    font-family:"Times New Roman", Times, serif; 
    font-size:16px; 
    color:#9900FF; 

} 

#navbar li /* list items within navbar container */ 
{ 
    padding-left:20px; 
    padding-right:20px; 
    display:inline; 
    border-right:solid 2px #33FFFF; 
    border-left:solid 2px #33FFFF; 
} 

CSS#2

body /* this is to set the body element, but mostly used for removing margins. */ 
{ 
    margin:0px; 
    background-color:#666666; 
} 

#container /* this is our overall content container. */ 
{ 
    width:1000px; 
    margin-right:auto; 
    margin-left:auto; 
    background-color:#CCCCCC; 
    border-left:groove 5px #444; 
    border-right:groove 5px #444; 
    border-bottom:groove 5px #444; 
} 

.logo img /* this is logo on the right side. */ 
{ 
    height:100px; 
    width:200px; 
    float:left; 

} 

#header1 /* This is the header directly between the logos */ 
{ 
    height:96px; 
    width:592px; 
    font-family:Georgia, "Times New Roman", Times, serif; 
    font-size:48px; 
    float:left; 
    text-align:center; 
    alignment-baseline:middle; 
    border-left:dashed 4px #00F; 
    border-right:dashed 4px #00F; 
    border-bottom:dashed 4px #00F; 
} 
+0

これは役立つかもしれないが。コンテナやロゴの周りに境界線を置くと、スペースは消えます。 – danze

答えて

1

それは簡単です。あなたはそれがあるべきように、すべてのデフォルトCSSを設定し、「reset.css」...のようなものを必要とする必要がある...しかし、これは今の簡単な修正になります。

* 
{ 
    margin: 0; 
    padding: 0; 
} 
+0

reset.cssのヘルプとヒントをありがとう! – unnamed

0

があなたのCSSにこれを追加し、あなたは問題ないはずです。

#p1 p { 
    margin:0; 
} 

jsFiddle example。 p1 divの段落タグのデフォルトの余白が原因です。

+0

mucho gracias!私の心が今日気付いていないところでは、私はまだそれを試していなかった。 – unnamed

0

私は確認してくださいあなたのコードを更新しました: -

HTML

<title>Test</title> 
    <link href="body.css" rel="stylesheet" type="text/css"> 
    <link href="navbar1.css" rel="stylesheet" type="text/css"> 
    </head> 

    <body> 
     <div id="navbar"> 
     <ul> 
     <li>black</li> 
     <li>blue</li> 
     <li>green</li> 
     <li>yellow</li> 
     <li>haha</li> 
     <li>good</li> 
     </ul> 
    </div><!-- End of navbar --> 
    <div id="container"> 
    <div class="logo"> 
      <img src="" alt="sun" /> 
    </div><!-- End of logo --> 

    <div id="header1"> 
      <span>Hello World</span> 
    </div><!-- End of header --> 

    <div class="logo"> 
      <img src="" alt="sun" /> 
    </div><!-- End of logo --> 
    <div id="p1"> 
      <p> up </p> 
    </div><!-- End of p1 --> 
     </div><!-- End of container --> 
    </body> 
    </html> 

CSS

body /* this is to set the body element, but mostly used for removing margins. */ 
{ 
    margin:0px; 
    padding:0px; 
    background-color:#666666; 
} 

#navbar /* navbar container */ 
{ 
    background-color:#999; 
    border-bottom:solid 3px #333; 
    margin:0px; 
} 
#navbar ul /* unordered lists withinin navbar container */ 
{ 
    width:1000px; 
    text-align:center; 
    margin-top:0px; 
    margin-bottom:0px; 
    list-style:none; 
    margin-left:auto; 
    margin-right:auto; 
    padding:0px; 
    font-family:"Times New Roman", Times, serif; 
    font-size:16px; 
    color:#9900FF; 

} 

#navbar li /* list items within navbar container */ 
{ 
    padding-left:20px; 
    padding-right:20px; 
    display:inline; 
    border-right:solid 2px #33FFFF; 
    border-left:solid 2px #33FFFF; 
} 

#container /* this is our overall content container. */ 
{ 
    width:1000px; 
    margin:auto; 
    background-color:#CCCCCC; 
    border-left:groove 5px #444; 
    border-right:groove 5px #444; 
    border-bottom:groove 5px #444; 
} 

.logo img /* this is logo on the right side. */ 
{ 
    height:100px; 
    width:200px; 
    float:left; 

} 

#header1 /* This is the header directly between the logos */ 
{ 
    height:96px; 
    width:592px; 
    font-family:Georgia, "Times New Roman", Times, serif; 
    font-size:48px; 
    float:left; 
    text-align:center; 
    alignment-baseline:middle; 
    border-left:dashed 4px #00F; 
    border-right:dashed 4px #00F; 
    border-bottom:dashed 4px #00F; 
} 

私はマージン、パディング追加しました:0;あなたのCSSで、それはあなたのデフォルト余裕のパディングが保存されますので、あなたがreset.cssを使用することができます....

はデモを参照してください - http://jsfiddle.net/6xuSp/35/

関連する問題