2017-10-15 1 views
0

を変更したとき、私はFlexboxesを使用して、次のHTML/CSSコードを持っている:揃えフレキシボックスの表示サイズが

*{ 
 
font-family:Arial; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
    margin: 0 
 
} 
 
.flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap: nowrap; 
 
    height: 100%; 
 
    width: 100% 
 
} 
 
.flexbox .header{ 
 
    background: green; 
 
    border:solid; 
 
    font-size: 30; 
 
    font-weight: bold; 
 
    padding-left: 5; 
 
} 
 
.flexbox .main { 
 
    flex: 1; 
 
    background: red; 
 
    position: relative 
 
} 
 

 
.flexbox-row { 
 
    display: flex; 
 
    position:absolute; 
 
    height: 100%; 
 
    width: 100% 
 
} 
 
.flexbox-row .links 
 
{ 
 
    background: yellow; 
 
    width:15%; 
 
    height:100%; 
 
} 
 
.flexbox-row .second { 
 
    flex: 1; 
 
    background: blue; 
 
    height:100%; 
 
} 
 

 

 
nav.sidenav { 
 
    margin:0; 
 
    background-color: white; 
 
    overflow: auto; 
 
    height:100%; 
 
} 
 

 

 
nav.sidenav a { 
 
    display: block; 
 
    color: black; 
 
    text-decoration: none; 
 
    padding: 8px; 
 
    text-align: center; 
 
} 
 

 
nav.sidenav a.active { 
 
    background-color: blue; 
 
    color: white; 
 
} 
 

 
nav.sidenav a:hover { 
 
    background-color: #555; 
 
    color: white; 
 
    text-decoration: underline; 
 
} 
 

 

 
@media screen and (max-width: 1000px) { 
 
    nav.sidenav { 
 
     width: 100%; 
 
     height: auto; 
 
     position: relative; 
 
     border-top:none; 
 
     border-bottom:solid; 
 
     margin-top:0; 
 
     } 
 
     nav.sidenav a { 
 
      float: left; 
 
      padding: 8px; 
 
     } 
 
    .flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap: initial; 
 
    width: 100% 
 
    } 
 
    .flexbox-row .links{ 
 
    width:100%; 
 
    } 
 
    .flexbox-row .second { 
 
    background: blue; 
 
} 
 

 
}
<div class="flexbox"> 
 

 
<div class="header">HeaderHeaderHeaderHeaderHeaderHeade</div> 
 

 
<div class="main"> 
 
    <div class="flexbox-row"> 
 
    <div class="links"> 
 
     navbar 
 
    </div> 
 
    
 
    <div class="second"> content</div> 
 
     
 
    </div> 
 
</div>

にはどうすれば表示幅を変更する際Flexboxesはこのように揃えることをアーカイブすることができます。 enter image description here

したがって、ヘッダーは同じままで、ナビゲーションバーとコンテンツになります。ブラウザの高さを入力します。 フレックスボックスを正しく使用する方法をcssとdontに教えてください。あなたのイメージに持っているものである - (flex-direction: column;>)、メディアクエリー(@media screen and (max-width: 1000px) {...)で

+0

私の答えは参考になりましたし、受け入れ、および/またはupvotedことができるなら、私に教えてください...またはそれは単に動作しませんでしたか? – LGSon

+0

私の答えがうまくいったり、役に立ったりしたという確認がなかったので、私はそれを削除しました。 – LGSon

+0

申し訳ありませんが、過去数日間インターネットにアクセスできませんでした。それにもかかわらず、あなたの答えを読むことに感謝します。 – Kitumijasi

答えて

1

2つの主なもの:

  • 狭い画面で、content
  • links以下の削除を置くために、メディアクエリを使用して、ここで修正スニペットがあります絶対位置指定とFlexboxを代わりに使用するので、内容に応じて適切にサイズ調整されます

私はCSSに多くのメモを追加しました。その内容と理由を説明しています。

* { 
 
    font-family: Arial; 
 
} 
 

 
html,body { 
 
    height: 100%; 
 
    margin: 0 
 
} 
 

 
.flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    /*flex-wrap: nowrap;   not needed, default value */ 
 
    height: 100%; 
 
    /*width: 100%     not needed, default behavior */ 
 
} 
 

 
.flexbox .header { 
 
    background: green; 
 
    border: solid; 
 
    font-size: 30; 
 
    font-weight: bold; 
 
    padding-left: 5px;   /* need unit, added "px" */ 
 
} 
 

 
.flexbox .main { 
 
    flex: 1; 
 
    background: red; 
 
    /*position: relative;   not needed anymore */ 
 
    display: flex;    /* instead of absolute position */ 
 
} 
 

 
.flexbox-row { 
 
    display: flex; 
 
    /*position: absolute;   not needed anymore */ 
 
    /*height: 100%;    not needed when parent has display: flex */ 
 
    width: 100%; 
 
} 
 

 
.flexbox-row .links { 
 
    background: yellow; 
 
    width: 15%; 
 
    /*height: 100%;    not needed when parent has display: flex */ 
 
} 
 

 
.flexbox-row .second { 
 
    flex: 1; 
 
    background: blue; 
 
    /*height: 100%;    not needed when parent has display: flex */ 
 
} 
 

 

 
nav.sidenav { 
 
    margin: 0; 
 
    background-color: white; 
 
    overflow: auto; 
 
    height: 100%; 
 
} 
 

 
nav.sidenav a { 
 
    display: block; 
 
    color: black; 
 
    text-decoration: none; 
 
    padding: 8px; 
 
    text-align: center; 
 
} 
 

 
nav.sidenav a.active { 
 
    background-color: blue; 
 
    color: white; 
 
} 
 

 
nav.sidenav a:hover { 
 
    background-color: #555; 
 
    color: white; 
 
    text-decoration: underline; 
 
} 
 

 
@media screen and (max-width: 1000px) { 
 
    nav.sidenav { 
 
    width: 100%; 
 
    height: auto; 
 
    position: relative; 
 
    border-top: none; 
 
    border-bottom: solid; 
 
    margin-top: 0; 
 
    } 
 
    nav.sidenav a { 
 
    float: left; 
 
    padding: 8px; 
 
    } 
 
    /* not needed, already set 
 
    .flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap: initial; 
 
    width: 100%; 
 
    } 
 
    */ 
 
    .flexbox-row { 
 
    flex-direction: column; /* added, put content below navbar */ 
 
    } 
 
    .flexbox-row .links { 
 
    width: 100%; 
 
    } 
 
    /* not needed, already set 
 
    .flexbox-row .second { 
 
    background: blue; 
 
    } 
 
    */ 
 
}
<div class="flexbox"> 
 

 
    <div class="header">HeaderHeaderHeaderHeaderHeaderHeader</div> 
 

 
    <div class="main"> 
 
    <div class="flexbox-row"> 
 
     <div class="links"> 
 
     navbar 
 
     </div> 
 
     <div class="second"> 
 
     content 
 
     </div> 
 
    </div> 
 
    </div> 
 
    
 
</div>

+1

ありがとう、私が必要なすべてを解決! – Kitumijasi

1

、お互いの下に(すなわち.links.second.flexbox-rowの子要素を配置

.flexbox-row { 
    flex-direction: column; 
} 

を追加。

*{ 
 
font-family:Arial; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
    margin: 0 
 
} 
 
.flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap: nowrap; 
 
    height: 100%; 
 
    width: 100% 
 
} 
 
.flexbox .header{ 
 
    background: green; 
 
    border:solid; 
 
    font-size: 30; 
 
    font-weight: bold; 
 
    padding-left: 5; 
 
} 
 
.flexbox .main { 
 
    flex: 1; 
 
    background: red; 
 
    position: relative 
 
} 
 

 
.flexbox-row { 
 
    display: flex; 
 
    position:absolute; 
 
    height: 100%; 
 
    width: 100% 
 
} 
 
.flexbox-row .links 
 
{ 
 
    background: yellow; 
 
    width:15%; 
 
    height:100%; 
 
} 
 
.flexbox-row .second { 
 
    flex: 1; 
 
    background: blue; 
 
    height:100%; 
 
} 
 

 

 
nav.sidenav { 
 
    margin:0; 
 
    background-color: white; 
 
    overflow: auto; 
 
    height:100%; 
 
} 
 

 

 
nav.sidenav a { 
 
    display: block; 
 
    color: black; 
 
    text-decoration: none; 
 
    padding: 8px; 
 
    text-align: center; 
 
} 
 

 
nav.sidenav a.active { 
 
    background-color: blue; 
 
    color: white; 
 
} 
 

 
nav.sidenav a:hover { 
 
    background-color: #555; 
 
    color: white; 
 
    text-decoration: underline; 
 
} 
 

 

 
@media screen and (max-width: 1000px) { 
 
    nav.sidenav { 
 
     width: 100%; 
 
     height: auto; 
 
     position: relative; 
 
     border-top:none; 
 
     border-bottom:solid; 
 
     margin-top:0; 
 
     } 
 
     nav.sidenav a { 
 
      float: left; 
 
      padding: 8px; 
 
     } 
 
    .flexbox { 
 
    display: flex; 
 
    flex-direction: column; 
 
    flex-wrap: initial; 
 
    width: 100% 
 
    } 
 
    .flexbox-row .links{ 
 
    width:100%; 
 
    } 
 
    .flexbox-row .second { 
 
    background: blue; 
 
} 
 
.flexbox-row { 
 
    flex-direction: column; 
 
} 
 
}
<div class="flexbox"> 
 

 
<div class="header">HeaderHeaderHeaderHeaderHeaderHeade</div> 
 

 
<div class="main"> 
 
    <div class="flexbox-row"> 
 
    <div class="links"> 
 
     navbar 
 
    </div> 
 
    
 
    <div class="second"> content</div> 
 
     
 
    </div> 
 
</div>

関連する問題