2017-03-02 1 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는 100 픽셀의 높이를 가지고있다. 따라서 아래 div 초 100 픽셀부터 시작해야합니다. navbar이 후 처음 div에 추가 :

style="top:100px;" 

그런 다음 그것을 작동합니다. 그 결과는 다음과 같습니다

<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 클래스를 생성하는 것입니다. 그런 다음 당신은 또한

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;

추가

일까요? 네비게이션 바 높이가 100px였습니다. 그래서 나는 display-bar-1 클래스에 100px의 여백을 주었다.

호프가 호프로 문제를 해결했습니다.

관련 문제