2017-07-07 2 views
0

フレックスボックスを使用して、垂直ナビゲーションバーの下部にある最後のアイテムを配置しようとしています。フレックスボックスを使ってこれを行う方法はありますか?ここでflexboxを使用して最後の要素を列の最後に配置するにはどうすればよいですか?

navbar

コードの例です:

<!doctype html> 
<html> 
<style> 
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
} 
ul { 
    list-style: none; 
    background: red; 
    width: 100px; 
    min-height: 100vh; 
    display: flex; 
    flex-direction: column; 
    align-items: flex-start; 
} 

li { 
    border: 1px solid blue; 
} 

li:last-child { 
    background: blue; 
    align-self: end; 
} 

</style> 
<body> 
<ul> 
    <li>foo</li> 
    <li>foo</li> 
    <li>foo</li> 
    <li>foo</li> 
    <li>foo</li> 
    <li>foo</li> 
</ul> 
</body> 
</html> 

答えて

2

margin-top: autoは一番下にそれをプッシュします。 https://hackernoon.com/flexbox-s-best-kept-secret-bd3d892826b6

<!doctype html> 
 
<html> 
 
<style> 
 
    * { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
    } 
 
    ul { 
 
    list-style: none; 
 
    background: red; 
 
    width: 100px; 
 
    min-height: 100vh; 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: flex-start; 
 
    } 
 
    
 
    li { 
 
    border: 1px solid blue; 
 
    } 
 
    
 
    li:last-child { 
 
    background: blue; 
 
    margin-top: auto; 
 
    } 
 
</style> 
 

 
<body> 
 
    <ul> 
 
    <li>foo</li> 
 
    <li>foo</li> 
 
    <li>foo</li> 
 
    <li>foo</li> 
 
    <li>foo</li> 
 
    <li>foo</li> 
 
    </ul> 
 
</body> 
 

 
</html>

- あなたは自動マージンの、ここでフレキシボックスについての詳細を読むことができます
関連する問題