2017-10-13 18 views
0

main-content divを画面の水平ナビゲーションバーにリサイズするナビゲーションバーの下に移動したいとします。ナビゲーションが画面上で変更されたときにdivを別のものに移動する

私はこのような単純な何かがうまくいくと仮定:

@media screen and (max-width: 540px) { 
    #main-content{ 
    display:block; 
    width:100%; 
    } 
} 

しかし、両方のdivを並べて表示されます。水平バーになるとすぐに、自分のナビゲーションバーでmain-contentを移動させるにはどうすればよいですか?ここで

は、問題を実証私の現在のアプローチです:

.site-wrapper { 
 
    height: 100%; 
 
    min-height: 100%; 
 
    display: flex; 
 
} 
 

 

 
/* NAVIGATION */ 
 

 
.nav-container { 
 
    border-right: 1px solid #E4E2E2; 
 
    height: 100%; 
 
    width: 200px; 
 
    background-color: #f4f3f3; 
 
} 
 

 
.logo-holder { 
 
    text-align: center; 
 
} 
 

 
.nav { 
 
    text-align: justify; 
 
} 
 

 
.nav-link { 
 
    display: block; 
 
    text-align: left; 
 
    color: #333; 
 
    text-decoration: none; 
 
    margin-left: 0px; 
 
    padding-left: 15px; 
 
} 
 

 
.nav-link:hover { 
 
    background-color: #333; 
 
    color: #f4f3f3; 
 
} 
 

 
.nav ul { 
 
    width: 100%; 
 
    padding: 0px; 
 
} 
 

 
.nav ul li { 
 
    margin-left: 5px; 
 
    list-style-type: none; 
 
    height: 25px; 
 
} 
 

 
.nav ul li a { 
 
    text-align: left; 
 
    padding: 5px; 
 
    color: #333; 
 
    text-decoration: none; 
 
    margin-left: 15px; 
 
} 
 

 
.nav li:hover a { 
 
    color: #f4f3f3; 
 
} 
 

 

 
/* MAIN CONTENT */ 
 

 
#main-content { 
 
    float: left; 
 
    margin: 10px; 
 
    border: 1px solid black; 
 
    width: 80%; 
 
    height: 500px; 
 
} 
 

 
@media screen and (max-width: 540px) { 
 
    #main-content { 
 
    display: block; 
 
    width: 100%; 
 
    } 
 
} 
 

 
.reg-div { 
 
    border: 1px solid red; 
 
    width: 80%; 
 
} 
 

 
.reg-div ul li { 
 
    list-style: none; 
 
    text-decoration: none; 
 
    color: #333; 
 
} 
 

 

 
/* MEDIA QUERIES */ 
 

 
@media screen and (max-width: 540px) { 
 
    .nav-container { 
 
    width: 100%; 
 
    height: 100px; 
 
    background-color: #f4f3f3; 
 
    border-bottom: 0.5px solid #f4f3f3; 
 
    } 
 
    .nav-link { 
 
    padding: 10px; 
 
    } 
 
    .logo-holder { 
 
    overflow: hidden; 
 
    display: block; 
 
    width: 40%; 
 
    } 
 
    .nav-container nav ul { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    justify-content: center; 
 
    } 
 
    .logo-holder { 
 
    text-align: left; 
 
    } 
 
    #navigation-div { 
 
    background-color: #f4f3f3; 
 
    margin-top: 0; 
 
    } 
 
}
<div class="site-wrapper"> 
 
    <!-- NAV-CONTAINER - LEFT OF PAGE --> 
 
    <div class="nav-container"> 
 
    <div class="logo-holder"> 
 
     <img class="user-select-none" width="150px" height="150px" src="" alt="logo here" /> 
 
    </div> 
 
    <div id="navigation-div"> 
 
     <nav class="nav"> 
 
     <ul class="nav-ul"> 
 
      <a class="nav-link active" href=""> 
 
      <li>test 1</li> 
 
      </a> 
 
      <a class="nav-link " href=""> 
 
      <li>test 2</li> 
 
      </a> 
 
      <a class="nav-link" href=""> 
 
      <li>test 3</li> 
 
      </a> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    </div> 
 
    <!-- NAV-CONTAINER END --> 
 

 
    <div id="main-content"> 
 
    <div class="reg-div"> 
 
     <ul> 
 
     <li><a href="">Login</a> | <a href="">Sign Up</a></li> 
 
     </ul> 
 
    </div> 
 
    <!-- MAIN CONTENT END --> 
 
    </div>

JSフィドル:https://jsfiddle.net/gtLhje4z/

答えて

0

あなたはフレキシボックスであるためにあなたの.site-wrapperを設定しているので、メディアクエリを追加しますラッパーの場合はflex-direction: columnmax-width: 540pxとなります。デフォルトでは、flexboxは1行に設定されています。

また、フレックスボックスがすべての作業を行うので、あなたは '#main-content'をフロートする必要はありません。

.site-wrapper { 
 
    height: 100%; 
 
    min-height: 100%; 
 
    display: flex; 
 
} 
 

 
@media screen and (max-width: 540px) { 
 
    .site-wrapper { 
 
     flex-direction: column; 
 
    } 
 
} 
 

 

 
/* NAVIGATION */ 
 

 
.nav-container { 
 
    border-right: 1px solid #E4E2E2; 
 
    height: 100%; 
 
    width: 200px; 
 
    background-color: #f4f3f3; 
 
} 
 

 
.logo-holder { 
 
    text-align: center; 
 
} 
 

 
.nav { 
 
    text-align: justify; 
 
} 
 

 
.nav-link { 
 
    display: block; 
 
    text-align: left; 
 
    color: #333; 
 
    text-decoration: none; 
 
    margin-left: 0px; 
 
    padding-left: 15px; 
 
} 
 

 
.nav-link:hover { 
 
    background-color: #333; 
 
    color: #f4f3f3; 
 
} 
 

 
.nav ul { 
 
    width: 100%; 
 
    padding: 0px; 
 
} 
 

 
.nav ul li { 
 
    margin-left: 5px; 
 
    list-style-type: none; 
 
    height: 25px; 
 
} 
 

 
.nav ul li a { 
 
    text-align: left; 
 
    padding: 5px; 
 
    color: #333; 
 
    text-decoration: none; 
 
    margin-left: 15px; 
 
} 
 

 
.nav li:hover a { 
 
    color: #f4f3f3; 
 
} 
 

 

 
/* MAIN CONTENT */ 
 

 
#main-content { 
 

 
    margin: 10px; 
 
    border: 1px solid black; 
 
    width: 80%; 
 
    height: 500px; 
 
} 
 

 
@media screen and (max-width: 540px) { 
 
    #main-content { 
 
    display: block; 
 
    width: 100%; 
 
    } 
 
} 
 

 
.reg-div { 
 
    border: 1px solid red; 
 
    width: 80%; 
 
} 
 

 
.reg-div ul li { 
 
    list-style: none; 
 
    text-decoration: none; 
 
    color: #333; 
 
} 
 

 

 
/* MEDIA QUERIES */ 
 

 
@media screen and (max-width: 540px) { 
 
    .nav-container { 
 
    width: 100%; 
 
    height: 100px; 
 
    background-color: #f4f3f3; 
 
    border-bottom: 0.5px solid #f4f3f3; 
 
    } 
 
    .nav-link { 
 
    padding: 10px; 
 
    } 
 
    .logo-holder { 
 
    overflow: hidden; 
 
    display: block; 
 
    width: 40%; 
 
    } 
 
    .nav-container nav ul { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    justify-content: center; 
 
    } 
 
    .logo-holder { 
 
    text-align: left; 
 
    } 
 
    #navigation-div { 
 
    background-color: #f4f3f3; 
 
    margin-top: 0; 
 
    } 
 
}
<div class="site-wrapper"> 
 
    <!-- NAV-CONTAINER - LEFT OF PAGE --> 
 
    <div class="nav-container"> 
 
    <div class="logo-holder"> 
 
     <img class="user-select-none" width="150px" height="150px" src="" alt="logo here" /> 
 
    </div> 
 
    <div id="navigation-div"> 
 
     <nav class="nav"> 
 
     <ul class="nav-ul"> 
 
      <a class="nav-link active" href=""> 
 
      <li>test 1</li> 
 
      </a> 
 
      <a class="nav-link " href=""> 
 
      <li>test 2</li> 
 
      </a> 
 
      <a class="nav-link" href=""> 
 
      <li>test 3</li> 
 
      </a> 
 
     </ul> 
 
     </nav> 
 
    </div> 
 
    </div> 
 
    <!-- NAV-CONTAINER END --> 
 

 
    <div id="main-content"> 
 
    <div class="reg-div"> 
 
     <ul> 
 
     <li><a href="">Login</a> | <a href="">Sign Up</a></li> 
 
     </ul> 
 
    </div> 
 
    <!-- MAIN CONTENT END --> 
 
    </div>

関連する問題