2017-03-02 6 views
0

CSSの反応を覚えようとしていますが、いくつかの基本的なcssデザインでは問題があります。私はあなたが下のコードで見ることができるように、固定のnavbarを作成しました。しかし、私が直面している問題は、コンテンツを適切に配置することができないということです。コンテンツは、ナビゲーションバーによってオーバーラップしています。適切なCSS修正を提案できますが、固定高さの空のdivを追加するなどの回避策はありませんか?ここでは、コードは次のようになります。CSS - Fixed Navbarの下にコンテンツを整えよう

*{ 
 
     box-sizing: border-box; 
 
    } 
 
    
 
    body{ 
 
     margin:0px; 
 
     padding: 0px; 
 
     background-color: darkgrey; 
 
    } 
 
    
 
    .title-bar{ 
 
     position:fixed; 
 
     margin-top:0px; 
 
     z-index: 100; 
 
     opacity: 1; 
 
     background-color:white; 
 
     width: 100%; 
 
     height: 100px; 
 
     border-bottom: solid 4px dodgerblue; 
 
    } 
 
    
 
    .page-container{ 
 
     padding: 0px; 
 
    } 
 
    
 
    .menu-options{ 
 
     list-style-type:none; 
 
    } 
 
    
 
    .menu-options li{ 
 
     display: inline; 
 
     padding: 10px; 
 
    } 
 
    
 
    .menu-options li:hover{ 
 
     background-color: deepskyblue; 
 
    } 
 
    
 
    .menu-options li a{ 
 
     color: black; 
 
     text-decoration:none; 
 
    } 
 
    
 
    .clear20{ 
 
     height: 40px; 
 
     clear: both; 
 
    } 
 
    
 
    .clear10{ 
 
     height: 20px; 
 
     clear: both; 
 
    } 
 
    
 
    .display-bar-1{ 
 
     background-color: deepskyblue; 
 
     height: 200px; 
 
     padding:40px; 
 
     position: relative; 
 
    } 
 
    
 
    html { 
 
     font-family: "Lucida Sans", sans-serif; 
 
    } 
 
    
 
    .caps { 
 
     text-transform: uppercase; 
 
    } 
 
    
 
    .register_button{ 
 
     text-align:center; 
 
     padding-top:20px; 
 
     padding-bottom:10px; 
 
     width: 200px; 
 
     height: 70px; 
 
     border: solid 3px white; 
 
     font-style:bold; 
 
     font-size:14pt; 
 
    
 
    } 
 
    
 
    .register_button:hover{ 
 
     background-color:navajowhite; 
 
     color: white; 
 
     cursor:pointer; 
 
     border-color: black; 
 
    }
<!DOCTYPE html> 
 
    <html> 
 
    <head> 
 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/> 
 
     <link href="responsive.css" rel="stylesheet"> 
 
    </head> 
 
    
 
    <body> 
 
     <div class="page-container"> 
 
    
 
      <div class="title-bar"> 
 
       <table width="100%"> 
 
        <tr> 
 
         <td><h1> Multirater Surveys </h1></td> 
 
         <td> 
 
          <ul class="menu-options"> 
 
           <li> <a href="#"> Home </a></li> 
 
           <li> <a href="#"> How It Works </a></li> 
 
           <li> <a href="#"> Features </a></li> 
 
           <li> <a href="#"> Surveys </a></li> 
 
           <li> <a href="#"> Plans and Pricings </a></li> 
 
           <li> <a href="#"> Webinars </a></li> 
 
           <li> <a href="#"> Blog </a></li> 
 
          </ul> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
      </div> 
 
    
 
    
 
      <div class="display-bar-1"> 
 
       <div class="row"> 
 
        <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
         World Class Service <br> 
 
         More Than 100 Clients 
 
        </div> 
 
        <div class="" style="padding:15px;float:left;width:40%;"> 
 
         <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-2"> 
 
       <div> 
 
        <h1> Some random block of texts </h1> 
 
        <p> Hello world how are you ? what is going on? </p> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-1"> 
 
       <div class="row"> 
 
        <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
         World Class Service <br> 
 
         More Than 100 Clients 
 
        </div> 
 
        <div class="" style="padding:15px;float:left;width:40%;"> 
 
         <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-2"> 
 
       <div> 
 
        <h1> Some random block of texts </h1> 
 
        <p> Hello world how are you ? what is going on? </p> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-1"> 
 
       <div class="row"> 
 
        <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
         World Class Service <br> 
 
         More Than 100 Clients 
 
        </div> 
 
        <div class="" style="padding:15px;float:left;width:40%;"> 
 
         <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-2"> 
 
       <div> 
 
        <h1> Some random block of texts </h1> 
 
        <p> Hello world how are you ? what is going on? </p> 
 
       </div> 
 
      </div> 
 
    
 
      <div class="display-bar-2"> 
 
       <div> 
 
        <h1> Some random block of texts </h1> 
 
        <p> Hello world how are you ? what is going on? </p> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    
 
     <input type="text" class="caps"/> 
 
    
 
     <script> 
 
     window.onload = function(){ 
 
      document.getElementById("register").onclick = function(){ 
 
       window.location = "https://www.google.com"; 
 
      } 
 
     } 
 
     </script> 
 
    </body> 
 
    
 
    </html> 
 

 
`responsive.html` 
 

 

答えて

0

あなたnavbarは100pxにの高さを有します。だから、あなたのdiv秒100pxから始める必要があります。

style="top:100px;" 

そして、それが動作するはずです: はこのnavbar後の最初のdivに追加します。それは次のようになります。

<div class="display-bar-1" style="top:100px;"> 
     <div class="row"> 
      <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
       World Class Service <br> 
       More Than 100 Clients 
      </div> 
      <div class="" style="padding:15px;float:left;width:40%;"> 
       <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
      </div> 
     </div> 
    </div> 

他の方法はnavbar後の最初のdivのために自分のcssクラスを作成することです。そして、あなたはまた、適切な方法での高さと同じパディング、あなたのdivにパディングトップを追加することです

padding-top:100px; 

または

margin-top:100px; 

\t \t \t \t \t *{ 
 
    box-sizing: border-box; 
 
} 
 

 
body{ 
 
    margin:0px; 
 
    padding: 0px; 
 
    background-color: darkgrey; 
 
} 
 

 
.title-bar{ 
 
    position:fixed; 
 
    margin-top:0px; 
 
    z-index: 100; 
 
    opacity: 1; 
 
    background-color:white; 
 
    width: 100%; 
 
    height: 100px; 
 
    border-bottom: solid 4px dodgerblue; 
 
} 
 

 
.page-container{ 
 
    padding: 0px; 
 
} 
 

 
.menu-options{ 
 
    list-style-type:none; 
 
} 
 

 
.menu-options li{ 
 
    display: inline; 
 
    padding: 10px; 
 
} 
 

 
.menu-options li:hover{ 
 
    background-color: deepskyblue; 
 
} 
 

 
.menu-options li a{ 
 
    color: black; 
 
    text-decoration:none; 
 
} 
 

 
.clear20{ 
 
    height: 40px; 
 
    clear: both; 
 
} 
 

 
.clear10{ 
 
    height: 20px; 
 
    clear: both; 
 
} 
 

 
.display-bar-1{ 
 
    background-color: deepskyblue; 
 
    height: 200px; 
 
    padding:40px; 
 
    position: relative; 
 
} 
 

 
html { 
 
    font-family: "Lucida Sans", sans-serif; 
 
} 
 

 
.caps { 
 
    text-transform: uppercase; 
 
} 
 

 
.register_button{ 
 
    text-align:center; 
 
    padding-top:20px; 
 
    padding-bottom:10px; 
 
    width: 200px; 
 
    height: 70px; 
 
    border: solid 3px white; 
 
    font-style:bold; 
 
    font-size:14pt; 
 

 
} 
 

 
.register_button:hover{ 
 
    background-color:navajowhite; 
 
    color: white; 
 
    cursor:pointer; 
 
    border-color: black; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/> 
 
    <link href="responsive.css" rel="stylesheet"> 
 
</head> 
 

 
<body> 
 
    <div class="page-container"> 
 

 
     <div class="title-bar"> 
 
      <table width="100%"> 
 
       <tr> 
 
        <td><h1> Multirater Surveys </h1></td> 
 
        <td> 
 
         <ul class="menu-options"> 
 
          <li> <a href="#"> Home </a></li> 
 
          <li> <a href="#"> How It Works </a></li> 
 
          <li> <a href="#"> Features </a></li> 
 
          <li> <a href="#"> Surveys </a></li> 
 
          <li> <a href="#"> Plans and Pricings </a></li> 
 
          <li> <a href="#"> Webinars </a></li> 
 
          <li> <a href="#"> Blog </a></li> 
 
         </ul> 
 
        </td> 
 
       </tr> 
 
      </table> 
 
     </div> 
 

 

 
     <div class="display-bar-1" style="top:100px;"> 
 
      <div class="row"> 
 
       <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
        World Class Service <br> 
 
        More Than 100 Clients 
 
       </div> 
 
       <div class="" style="padding:15px;float:left;width:40%;"> 
 
        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
       </div> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-2"> 
 
      <div> 
 
       <h1> Some random block of texts </h1> 
 
       <p> Hello world how are you ? what is going on? </p> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-1"> 
 
      <div class="row"> 
 
       <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
        World Class Service <br> 
 
        More Than 100 Clients 
 
       </div> 
 
       <div class="" style="padding:15px;float:left;width:40%;"> 
 
        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
       </div> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-2"> 
 
      <div> 
 
       <h1> Some random block of texts </h1> 
 
       <p> Hello world how are you ? what is going on? </p> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-1"> 
 
      <div class="row"> 
 
       <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;"> 
 
        World Class Service <br> 
 
        More Than 100 Clients 
 
       </div> 
 
       <div class="" style="padding:15px;float:left;width:40%;"> 
 
        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div> 
 
       </div> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-2"> 
 
      <div> 
 
       <h1> Some random block of texts </h1> 
 
       <p> Hello world how are you ? what is going on? </p> 
 
      </div> 
 
     </div> 
 

 
     <div class="display-bar-2"> 
 
      <div> 
 
       <h1> Some random block of texts </h1> 
 
       <p> Hello world how are you ? what is going on? </p> 
 
      </div> 
 
     </div> 
 
    </div> 
 

 
    <input type="text" class="caps"/> 
 

 
    <script> 
 
    window.onload = function(){ 
 
     document.getElementById("register").onclick = function(){ 
 
      window.location = "https://www.google.com"; 
 
     } 
 
    } 
 
    </script> 
 
</body> 
 

 
</html>

0

で仕事ができますあなたの固定ヘッダー。

1

responsive.cssファイルにいくつかの変更を加えてくれました。

私はtop: 0;

なぜmargin-top:0px;を変更

.title-bar{ 
    position:fixed; 
    top: 0; 
    z-index: 100; 
    opacity: 1; 
    background-color:white; 
    width: 100%; 
    height: 100px; 
    border-bottom: solid 4px dodgerblue; 
} 

タイトルバークラス:

ここで私が行った変更はありますか?

とでhereを言ったように、その最も近い位置する祖先の上端の下方に0に固定配置ナビゲーションバーの上端を設定する表示バー-1

.display-bar-1{ 
    background-color: deepskyblue; 
    height: 200px; 
    margin-top: 100px; 
    padding:40px; 
    position: relative; 
} 

Iはmargin-top: 100px;

を添加

なぜ?あなたのnavbarの高さは100pxでした。だから私はあなたのdisplay-bar-1クラスに100pxの余白を付けました。

これがあなたの問題を解決することを願っています。

関連する問題