2016-05-25 8 views
0

私は、2つのボックスクラスのdivの位置をjustify-contentで指定したいと思います。flex-endですが、上記の残りのスペースに垂直方向にimg-container divを垂直に配置したいのですが、これが可能であれば、好ましくはjavascriptなしではわかりません。ディスプレイでの画像の位置/ divの高さflex

レイアウトは、縦向きのモバイルデバイス向けです。コンテンツを正当化するのは最善のアプローチではないかもしれませんが、フォーム要素を画面の下部に配置して配置するレイアウトが欲しいですが、ロゴ領域からスペースを取って小さなデバイスに応答します。

.flexcontainer { 
 
    display: -webkit-flex; 
 
    display: flex; 
 
    -webkit-flex-direction: column; 
 
    flex-direction: column;  
 
    -webkit-align-items: center; 
 
    align-items: center; 
 
    -webkit-justify-content: flex-end; 
 
    justify-content: flex-end; 
 
    
 
    /*iPhone 4*/ 
 
    height: 480px; 
 
    width:320px; 
 
    /*iPhone 6*/ 
 
    /*height: 667px; 
 
    width:375px;*/ 
 
    
 
    background-color: blue; 
 
    border: 1px solid red; 
 
} 
 

 
.box { 
 
    text-align:center; 
 
    height: auto; 
 
    width: 100%; 
 
    background-color: green; 
 
    border: 1px solid pink; 
 
    margin: 3px; 
 
    padding-top:20px; 
 
    padding-bottom:20px; 
 
    margin-top:20px; 
 
    margin-bottom:20px; 
 
} 
 

 
.img-container{ 
 
    text-align:center; 
 
}
<div class="flexcontainer"> 
 
<div class="img-container"> 
 
<img src='https://wiki.maemo.org/images/thumb/d/de/Maemo.org_logo_contest_sample1_bundyo.png/300px-Maemo.org_logo_contest_sample1_bundyo.png' width='80%'/> 
 
</div> 
 

 
<div class="box"> 
 
    <input type="text" placeholder="username"> 
 
    <br> 
 
    <input type="password" placeholder="password"> 
 
    <br> 
 
    <button>submit</button> 
 
</div> 
 
<div class="box"> 
 
    <button>password reset</button> 
 
    <br> 
 
    <button>register</button> 
 
</div> 
 

 
</div>

答えて

1

あなたは、コードの少しだけを変更し、あなたが望むものを達成できます。

フィドル:だから、これは下のボックスと同じ性質を取る

<div class="box clear img-container"> 
    <img src='https://wiki.maemo.org/images/thumb/d/de/Maemo.org_logo_contest_sample1_bundyo.png/300px-Maemo.org_logo_contest_sample1_bundyo.png' width='80%'/> 
</div> 

https://jsfiddle.net/gczcorn0/

私はこのようになり、あなたのイメージコンテナを変更しました。その後、私はあなたがこれだけCSSをクリア画像ボックスのbackground-colorborderをしたくないと仮定は次のように属性:

.box.clear { 
    background-color: transparent; 
    border: none; 
} 

私はあなたはそれがより小型のデバイスで動作する方法によって何を意味するのかわからないんだけどこの例では幅が320pxに設定されているためです。コメントをもとに

EDIT:

この更新フィドルは、あなたがコメントで表現状況で何ができるかを示していますhttps://jsfiddle.net/gczcorn0/2/

+0

返信用のおかげで、私は少し良く私は小さなデバイスを検討したいiphone 4サイズに設定コンテナの幅を持っている最後のビットを説明している必要があります。 iphone 4の高さ/幅をCSSでコメントアウトし、iphone 6サイズを使用すると、ロゴはあなたのjsfiddleで中央から外れます。私は、高さが変わると、空のスペースにロゴを垂直に配置することを望んでいました。 https://jsfiddle.net/gczcorn0/1/ – mao

+0

さて、私はそれを取得します。私はあなたのために私の答えを更新し、うまくいけばそれは今あなたが欲しいものです:) – thepio

+0

偉大なthatsちょうどそれよりも良い – mao

1

あなたにもimg-containerdisplay: flexを使用することができます。

.flexcontainer { 
 
    display: -webkit-flex; 
 
    display: flex; 
 
    -webkit-flex-direction: column; 
 
    flex-direction: column;  
 
    -webkit-align-items: center; 
 
    align-items: center; 
 
    -webkit-justify-content: flex-end; 
 
    justify-content: flex-end; 
 

 
    /*iPhone 4 */ 
 
    height: 480px; 
 
    width:320px; 
 

 
    /*iPhone 6 
 
    height: 667px; 
 
    width:375px;*/ 
 

 
    background-color: blue; 
 
    border: 1px solid red; 
 
} 
 

 
.box { 
 
    text-align:center; 
 
    height: auto; 
 
    width: 100%; 
 
    background-color: green; 
 
    border: 1px solid pink; 
 
    margin: 3px; 
 
    padding-top:20px; 
 
    padding-bottom:20px; 
 
    margin-top:20px; 
 
    margin-bottom:20px; 
 
} 
 

 
.img-container{ 
 
    display: flex; 
 
    flex-flow: column nowrap; 
 
    justify-content: center; 
 
    flex: 1; 
 
} 
 

 
.img-container img { 
 
    margin: 0 auto; 
 
}
<div class="flexcontainer"> 
 
<div class="img-container"> 
 
<img src='https://wiki.maemo.org/images/thumb/d/de/Maemo.org_logo_contest_sample1_bundyo.png/300px-Maemo.org_logo_contest_sample1_bundyo.png' width='80%'/> 
 
</div> 
 

 
<div class="box"> 
 
    <input type="text" placeholder="username"> 
 
    <br> 
 
    <input type="password" placeholder="password"> 
 
    <br> 
 
    <button>submit</button> 
 
</div> 
 
<div class="box"> 
 
    <button>password reset</button> 
 
    <br> 
 
    <button>register</button> 
 
</div> 
 

 
</div>