I have li's
with the flexlayout
. There are 3 li's
in every column. (flex-basis
is set to a third.) In the li
I have a div
for a background image, and another div
to display text. I want the text to be below the image. The image should take up a majority of the room.
For some reason the image
isn't there. I set the image
height to 80%
, but when I run it and go to "inspect element" (in chrome), the div's
height is 0. When I set it to an amount with pixels, (not percentage), then it works.
My question is, how can I set the div
to a percentage and still have it shown?
html, body {
margin: 0;
height: 100%;
}
div {
align-items: center;
justify-content: center;
height: 100%;
display: flex;
overflow: auto;
background-color:aqua;
}
ul {
margin-top: auto;
margin-bottom: auto;
height: calc(70% + 0px);
padding: 0;
display: inline-flex;
flex-wrap: wrap;
flex-direction: column;
width: 100%;
align-content: flex-start;
}
li {
flex-basis: calc(100% / 3 - 2px);
/* Subtract the border */
color: firebrick;
border: 1px solid firebrick;
background-color: greenYellow;
margin: 0px;
list-style-type: none;
box-sizing: border-box;
background-size: contain;
width: 200px;
}
.image {
background-image: url("http://i.imgur.com/nswXRR4.jpg");
background-size: contain;
background-position: 50%, 50%;
background-repeat: no-repeat;
margin: 5px;
height: 90%;
}
<div>
<ul>
<li>
<div class="image"></div>
<div class="num">1</div>
</li>
<li>
<div class="image"></div>
<div class="num">2</div>
</li>
<li>
<div class="image"></div>
<div class="num">3</div>
</li>
<li>
<div class="image"></div>
<div class="num">4</div>
</li>
</ul>
</div>