I am putting together what should be a simple nav bar and styling with flex box. For some reason, instead of displaying as a row (horizontal), it is showing as a column (vertical).
I can make the links go horizontal using float:left, but then they don't stretch evenly to fill the nav bar.
My understanding is that flex-grow:1 should make each item occupy an equal amount of space. But this is not happening.
There are four declarations that are not working as expected:
flex-direction The links within the nav bar are in a column instead of a row
padding Although the nav bar's padding is set to zero, it still appears to have padding
text-align The text within each <li> is not getting horizontally centered
flex-grow The links are not spacing out evenly
I'm not sure if they are all stemming from to one problem, or each separate problems.
Here is a simplified snippet:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Curse of the Nav Bar</title>
<style>
nav {
display: flex;
flex-direction: row; /* not working */
background-color: #d2d6d6;
padding: 0; /* not working */
}
nav a {
display: flex;
text-decoration: none;
list-style: none;
border: 2px solid #727171;
color: #727171;
background-color: #c4c4c4;
padding: 4px;
margin: 2px;
text-align: center; /* not working */
flex-grow: 1; /* not working */
}
nav a:hover,
nav a:active {
background-color: #aaa;
}
</style>
</head>
<body>
<nav>
<ul>
<a href="#"><li>Once</li></a>
<a href="#"><li>Upon</li></a>
<a href="#"><li>A Time</li></a>
<a href="#"><li>There</li></a>
<a href="#"><li>Was</li></a>
<a href="#"><li>A Problematic</li></a>
<a href="#"><li>Nav Bar</li></a>
</ul>
</nav>
</body>
</html>
I've used flex box plenty of times before, but never seen it behave like this.