2017-03-08 7 views
0

私はページを折り返して0と自動余白を960pxに設定しようとしましたが、何も動作しません。ページが中央にならない

body { 
 
    background-image: url('http://wallpapercave.com/wp/adsKXLw.png'); 
 
    background-repeat: no-repeat; 
 
    overflow: scroll; 
 
    background-size: cover; 
 
    height: 100%; 
 
} 
 

 
#everything { 
 
    margin: 0 auto; 
 
    width: 960px; 
 
} 
 

 
#huge { 
 
    width: 900px; 
 
    height: 100%; 
 
    position: absolute; 
 
    background-color: rgba(255, 103, 48, 0.5); 
 
    left: 75px; 
 
    top: 0%; 
 
} 
 

 
.navbar div, .navbar div p { 
 
    position: fixed; 
 
} 
 

 
#navbar-background { 
 
    width: 820px; 
 
    height: 110px; 
 
    border-radius: 70px; 
 
    top: 11px; 
 
    left: 115px; 
 
    background-color: rgba(255,255,255, .2); 
 
    z-index: 1 
 
} 
 

 
#home-div { 
 
    background-color: rgb(249, 162, 100); 
 
    width: 210px; 
 
    height: 60px; 
 
    border-radius: 30px; 
 
    position: fixed; 
 
    left: 135px; 
 
    top: 30px; 
 
    z-index: 2; 
 
    border-top: 1px white solid; 
 
    border-left: 1px solid white 
 
} 
 

 
#home-div-button { 
 
    background-color: rgb(200, 131, 78); 
 
    width: 215px; 
 
    height: 60px; 
 
    border-radius: 30px; 
 
    z-index: 1; 
 
    top: 40px; 
 
    left: 140px; 
 
    position: fixed; 
 
} 
 

 
#home-text { 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    top: 10px; 
 
    left: 145px; 
 
    font-size: 30px; 
 
    color: #FFFFFF; 
 
} 
 

 

 

 
#clan-div { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 505px; 
 
    top: 40px; 
 
    position: fixed; 
 
    border-radius: 10px 0px 0px 10px; 
 
} 
 

 
#clan-text { 
 
    left: 512px; 
 
    top: 35px; 
 
    font-size: 14px; 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    color: #FFFFFF; 
 
} 
 

 
#clan-div-2 { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 597px; 
 
    top: 40px; 
 
    position: fixed; 
 
    border-radius: 0px 10px 10px 0px; 
 
} 
 

 
#clan-text-2 { 
 
    left: 610px; 
 
    top: 35px; 
 
    font-size: 14px; 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    color: #FFFFFF; 
 
} 
 

 
#games-div { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 712px; 
 
    top: 40px; 
 
    position: fixed; 
 
    border-radius: 10px; 
 
} 
 

 
#games-text { 
 
    font-size: 20px; 
 
    font-family: Comfortaa; 
 
    color: #FFFFFF; 
 
    top: 35px; 
 
    left: 723px; 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <title></title> 
 
    <link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet"> 
 
    <link href="style.css" rel="stylesheet" text="text/css"> 
 
    <link href="script-1.js" type="text/javascript"> 
 
    </head> 
 
    <body> 
 
    <div id="everything"> 
 
     <div id="huge"></div> 
 
     <div class="navbar"> 
 

 
     <div id="navbar-background"></div> 
 

 
     <div id="home-div"> 
 
      <p id="home-text"></p> 
 
     </div> 
 

 
     <div id="home-div-button"></div> 
 

 
     <div id="clan-div"> 
 
      <p id="clan-text"></p> 
 
     </div> 
 

 
     <div id="clan-div-2"> 
 
      <p id="clan-text-2"></p> 
 
     </div> 
 

 
     <div id="games-div"> 
 
      <p id="games-text"></p> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </body> 
 
</html>

スニペットを展開し、あなたはそれが左にこだわっている方法を見ていきます。私が相対位置に位置を置くと、ナビゲーションバーは上に固定されません。

答えて

1

さまざまなポジショニングタイプがどのように作用し、どのように子供に影響を与えるかを正確に読み取ることを強くおすすめします。私は以下のスニペットであなたが望む動作を想定して実装しましたが、主な変更は#everythingの最小の高さを与え、コンテナをdivを分離しない背景として使用しています。ご質問がありましたら、コメントを削除するのをためらってください。あなたがセンターを達成するためにwidthあなたラッピング要素のpositionpropertyの両方を設定する必要が

body { 
 
    background-image: url('http://wallpapercave.com/wp/adsKXLw.png'); 
 
    background-repeat: no-repeat; 
 
    overflow: scroll; 
 
    background-size: cover; 
 
    height: 100%; 
 
} 
 

 
#everything { 
 
    position: relative; 
 
    margin: 0 auto; 
 
    width: 960px; 
 
    min-height: 100vh; 
 
    background-color: rgba(255, 103, 48, 0.5); 
 
} 
 

 
#huge { 
 
    width: 900px; 
 
    height: 100%; 
 
    position: absolute; 
 
    background-color: rgba(255, 103, 48, 0.5); 
 
    left: 75px; 
 
    top: 0%; 
 
} 
 

 
.navbar { 
 
    position: fixed; 
 
    width: 960px; 
 
    height: 110px; 
 
    background-color: rgba(255,255,255, .2); 
 
    border-radius: 70px; 
 
} 
 

 
#home-div { 
 
    background-color: rgb(249, 162, 100); 
 
    width: 210px; 
 
    height: 60px; 
 
    border-radius: 30px; 
 
    position: absolute; 
 
    left: 135px; 
 
    top: 22px; 
 
    z-index: 2; 
 
    border-top: 1px white solid; 
 
    border-left: 1px solid white 
 
} 
 

 
#home-div-button { 
 
    background-color: rgb(200, 131, 78); 
 
    width: 215px; 
 
    height: 60px; 
 
    border-radius: 30px; 
 
    z-index: 1; 
 
    top: 32px; 
 
    left: 140px; 
 
    position: absolute; 
 
} 
 

 
#home-text { 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    top: 10px; 
 
    left: 145px; 
 
    font-size: 30px; 
 
    color: #FFFFFF; 
 
} 
 

 

 

 
#clan-div { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 505px; 
 
    top: 32px; 
 
    position: absolute; 
 
    border-radius: 10px 0px 0px 10px; 
 
} 
 

 
#clan-text { 
 
    left: 512px; 
 
    top: 35px; 
 
    font-size: 14px; 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    color: #FFFFFF; 
 
} 
 

 
#clan-div-2 { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 597px; 
 
    top: 32px; 
 
    position: absolute; 
 
    border-radius: 0px 10px 10px 0px; 
 
} 
 

 
#clan-text-2 { 
 
    left: 610px; 
 
    top: 35px; 
 
    font-size: 14px; 
 
    font-family: Comfortaa; 
 
    text-align: center; 
 
    color: #FFFFFF; 
 
} 
 

 
#games-div { 
 
    width: 90px; 
 
    height: 45px; 
 
    border: 2px white solid; 
 
    left: 712px; 
 
    top: 32px; 
 
    position: absolute; 
 
    border-radius: 10px; 
 
} 
 

 
#games-text { 
 
    font-size: 20px; 
 
    font-family: Comfortaa; 
 
    color: #FFFFFF; 
 
    top: 35px; 
 
    left: 723px; 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <title></title> 
 
    <link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet"> 
 
    <link href="style.css" rel="stylesheet" text="text/css"> 
 
    <link href="script-1.js" type="text/javascript"> 
 
    </head> 
 
    <body> 
 
    <div id="everything"> 
 
     <div class="navbar"> 
 
     <div id="home-div"> 
 
      <p id="home-text"></p> 
 
     </div> 
 

 
     <div id="home-div-button"></div> 
 

 
     <div id="clan-div"> 
 
      <p id="clan-text"></p> 
 
     </div> 
 

 
     <div id="clan-div-2"> 
 
      <p id="clan-text-2"></p> 
 
     </div> 
 

 
     <div id="games-div"> 
 
      <p id="games-text"></p> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </body> 
 
</html>

+0

ありがとうございました!私はあなたが何をしたのか、それがなぜ助けられたのかを本当に理解していません。あなたが変更した特定の属性はありますか? – BOBONA

+0

また、nav barが#hugeの全長を占めずに中央に配置されるようにする方法もわかりません。 .navの幅を短くして左に100pxを使用するようにしましたが、ブラウザをズームインまたはズームアウトしたときに正しくスケーリングを停止しました。 – BOBONA

0

。あなたと一緒にmargin: 0 auto;

ie。

.pagewrap { 
    width: 960px; 
    position: relative; 
    margin: 0 auto; 
    height: auto; 
} 

希望します。

関連する問題