Why does flex-grow: 1 not work here? I want the elements to share the whole space and there are no spaces between them. They should be navigation buttons to which you can add one if you need one more. If possible please use flex-box, I would like to understand it.
http://jsfiddle.net/vqL95o0s/1/
CSS
header{
background-color: #1D3557;
height: 300px;
background-repeat: repeat-x;
}
ul.navlist {
width: auto;
display: flex;
justify-content: space-between;
list-style-type: none;
align-items: flex-end;
padding: 0;
}
a.button {
height: 75px;
display: flex;
align-items: center;
flex-grow: 1;
background-color: black;
}
HTML
<header style="background-image: url('img/headerStripes.png')">
<img src="img/webdev_logo.png" alt="Logo">
<ul class="navlist">
<li><a class="button" href="#">Example</a></li>
<li><a class="button" href="#">Example 2</a></li>
<li><a class="button" href="#">Example 3</a></li>
<li><a class="button" href="#">Example 4</a></li>
<li><a class="button" href="#">Example 5</a></li>
<li><a class="button active">Example 6</a></li>
</ul>
</header>
The boxes stayed in one place at a distance, but did not get any bigger.
4
Answers
You need to set the flex-grow property for the li elements as they are the direct children of the navlist in which you want them to grow.
The problem is that, you are applying flex-grow property on "a element". You should apply the flex-grow on the direct child of flexbox that is li items. Here is the updated code:-
Here I applied flex-grow to the first li item.
You
a
tag is inside theli
element. This one should fill the space :http://jsfiddle.net/dL7nz9xw/
And you don’t need the
flex-grow: 1;
https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
Remove the
justify-content: space-between
on your.navlist
(or set it back tonormal
) and set theflex-grow: 1;
on yourli
elements rather than your anchors. Youra
are not flex items because they are not the direct children of yourul
. Hope it helps.