I tried to create a menu bar using flexbox to help myself understand it. I made the parent element a display:flex and the child elements also. I then made the elements align to the left.
Problem 1 I tried to make use of the align-self:flex-end property on the final element but this doesn't appear to work. The last element on the menu remains aligned to the left with the others. I have previously used margin:auto but I don't see why we would do that if we have this nice flex property instead? Using margin:auto just seems like a hack to me. (FYI the div is using margin for a different purpose).
Problem 2 As a test I changed the elements to but this changed the behaviour completely. Surely converting any html element to a flexbox converts it from display:block or display:inline as it would have been by default to being a flexbox? What am I not understanding here?
The Code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test 1 Flexbox</title>
<link rel="stylesheet" href="css/main.css">
<link rel="icon" href="images/favicon.png">
<style type="text/css">
div{
width:50em;
margin-left:auto;
margin-right:auto;
display:flex;
border:1px solid black;
}
nav{
display:flex;
width:50em;
flex-direction:column;
align-items:center; /*vertical*/
justify-content:left; /*horizontal*/
border:1px solid blue;
}
nav a{
width:6em;
display:flex;
border:1px solid green;
margin-right:1em;
}
#last{
align-self:flex-end;
}
@media ( min-width:37em )
{
nav{
flex-direction:row;
}
}
</style>
</head>
<body>
<div>
<nav>
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
<a href="#">Link 4</a>
<a id="last" href="#">Link 5</a>
</nav>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</body>
</html>