I have tried a little bit with flex-box and I don't understand something about it. Until now I thought that the value of the width property of a flex-box item doesn't matter as long as the flex-basis is set. I found this claim also in this Blog. But if I remove the width property of the div element, the result changes. Why? What exactly happens here?
flex-basis: 40px; and width: 40px; of div element set
flex-basis: 40px; and width: 40px; of div element not set
I also created a jsfiddle.
*flex-basis: 40px;* and *width: 40px;* of div element set:
*
{
margin: 0;
padding: 0;
list-style-type: none;
text-decoration: none;
}
section
{
display: inline-block;
}
ol
{
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
background-color: gray;
}
li
{
flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
background-color: greenyellow;
}
a
{
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
div /* Icon Placeholder */
{
flex-basis: 40px;
flex-grow: 0;
flex-shrink: 0;
width: 40px;
height: 40px;
background-color: red;
}
p
{
flex-basis: 0;
flex-grow: 1;
flex-shrink: 0;
}
<section>
<ol>
<li><a href="#"><div></div><p>The birch canoe slid on the smooth planks.</p></a></li>
<li><a href="#"><div></div><p>Glue the sheet to the dark blue background.</p></a></li>
<li><a href="#"><div></div><p>It's easy to tell the depth of a well.</p></a></li>
<li><a href="#"><div></div><p>These days a chicken leg is a rare dish.</p></a></li>
<li><a href="#"><div></div><p>Rice is often served in round bowls.</p></a></li>
</ol>
</section>
*flex-basis: 40px;* and *width: 40px;* of div element not set:
*
{
margin: 0;
padding: 0;
list-style-type: none;
text-decoration: none;
}
section
{
display: inline-block;
}
ol
{
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
background-color: gray;
}
li
{
flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
background-color: greenyellow;
}
a
{
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
div /* Icon Placeholder */
{
flex-basis: 40px;
flex-grow: 0;
flex-shrink: 0;
height: 40px;
background-color: red;
}
p
{
flex-basis: 0;
flex-grow: 1;
flex-shrink: 0;
}
<section>
<ol>
<li><a href="#"><div></div><p>The birch canoe slid on the smooth planks.</p></a></li>
<li><a href="#"><div></div><p>Glue the sheet to the dark blue background.</p></a></li>
<li><a href="#"><div></div><p>It's easy to tell the depth of a well.</p></a></li>
<li><a href="#"><div></div><p>These days a chicken leg is a rare dish.</p></a></li>
<li><a href="#"><div></div><p>Rice is often served in round bowls.</p></a></li>
</ol>
</section>