I have an HTML structure with several list items laid out using flexbox, and within them are several elements which I'm laying out using a nested flexbox.
In Chrome, IE11, and Edge, the heights of all the list items are effectively matched thanks to Flexbox and height: 100%
. The submit buttons ("add to basket") are therefore vertically aligned.
In Safari (desktop, ver 9.1.2) however, the height: 100%
isn't applying (it probably isn't seeing a parent height value to base from). As such, the boxes aren't of equal height, and my elements are not aligned.
How can I modify the CSS to have Safari match Chrome's rendering behaviour?
body {
padding: 0;
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
li {
padding: 0 10px;
flex: 1 1 25%;
}
figure {
margin: 0;
background-color: rgba(255, 0, 0, 0.25);
height: 100%; // this isn't working in safari
display: flex;
flex-direction: column;
a {
flex: 1;
flex-shrink: 0;
}
img {
display: block;
width: 100%;
}
}
figcaption {
height: 100%; // this isn't working in safari
flex: 1;
display: flex;
flex-direction: column;
}
.itemname {
flex: 1;
flex-grow: 1;
margin-bottom: 10px;
}
.price {
float: right;
font-weight: bold;
}
form {} select {
display: block;
width: 100%;
margin-bottom: 10px;
}
button[type='submit'] {
display: block;
width: 100%;
}
<ul>
<li>
<figure>
<a href="#">
<img src="http://placehold.it/400" />
</a>
<figcaption>
<div class="itemname"><span class="price">$10</span>Product</div>
<form>
<select>
<option selected>Please select</option>
</select>
<button type="submit">Add to Basket</button>
</form>
</figcaption>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="http://placehold.it/400" />
</a>
<figcaption>
<div class="itemname"><span class="price">$10</span>Product Two With A Much Longer Name That Could Wrap</div>
<form>
<select>
<option selected>Please select</option>
</select>
<button type="submit">Add to Basket</button>
</form>
</figcaption>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="http://placehold.it/400" />
</a>
<figcaption>
<div class="itemname"><span class="price">$10</span>Product Three No Select</div>
<form>
<button type="submit">Add to Basket</button>
</form>
</figcaption>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="http://placehold.it/400" />
</a>
<figcaption>
<div class="itemname"><span class="price">$10</span>Product</div>
<form>
<select>
<option selected>Please select</option>
</select>
<button type="submit">Add to Basket</button>
</form>
</figcaption>
</figure>
</li>
</ul>