I want to have a vertical menu with a specific height.
Each child must fill the height of the parent and have middle-aligned text.
The number of children is random, so I have to work with dynamic values.
Div .container
contains a random number of children (.item
) that always have to fill the height of the parent. To achieve that I used flexbox.
For making links with text aligned to the middle I am using display: table-cell
technique. But using table displays requires using a height 100%.
My problem is that .item-inner { height: 100% }
is not working in webkit (Chrome).
.item
fill the height of the parent with text vertical aligned to middle?Example here jsFiddle, should be viewed in Firefox and Chrome
.container {_x000D_
height: 20em;_x000D_
display: flex;_x000D_
flex-direction: column;_x000D_
border: 5px solid black_x000D_
}_x000D_
.item {_x000D_
flex: 1;_x000D_
border-bottom: 1px solid white;_x000D_
}_x000D_
.item-inner {_x000D_
height: 100%;_x000D_
width: 100%;_x000D_
display: table;_x000D_
}_x000D_
a {_x000D_
background: orange;_x000D_
display: table-cell;_x000D_
vertical-align: middle;_x000D_
}
_x000D_
<div class="container">_x000D_
<div class="item">_x000D_
<div class="item-inner">_x000D_
<a>Button</a>_x000D_
</div>_x000D_
</div>_x000D_
_x000D_
<div class="item">_x000D_
<div class="item-inner">_x000D_
<a>Button</a>_x000D_
</div>_x000D_
</div>_x000D_
_x000D_
<div class="item">_x000D_
<div class="item-inner">_x000D_
<a>Button</a>_x000D_
</div>_x000D_
</div>_x000D_
</div>
_x000D_
This question is related to
css
google-chrome
webkit
flexbox
I have had a similar issue in iOS 8, 9 and 10 and the info above couldn't fix it, however I did discover a solution after a day of working on this. Granted it won't work for everyone but in my case my items were stacked in a column and had 0 height when it should have been content height. Switching the css to be row and wrap fixed the issue. This only works if you have a single item and they are stacked but since it took me a day to find this out I thought I should share my fix!
.wrapper {
flex-direction: column; // <-- Remove this line
flex-direction: row; // <-- replace it with
flex-wrap: wrap; // <-- Add wrapping
}
.item {
width: 100%;
}
I had a similar bug, but while using a fixed number for height and not a percentage. It was also a flex container within the body (which has no specified height). It appeared that on Safari, my flex container had a height of 9px for some reason, but in all other browsers it displayed the correct 100px height specified in the stylesheet.
I managed to get it to work by adding both the height
and min-height
properties to the CSS class.
The following worked for me on both Safari 13.0.4 and Chrome 79.0.3945.130:
.flex-container {
display: flex;
flex-direction: column;
min-height: 100px;
height: 100px;
}
Hope this helps!
For Mobile Safari There is a Browser fix. you need to add -webkit-box for iOS devices.
Ex.
display: flex;
display: -webkit-box;
flex-direction: column;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
align-items: stretch;
if you're using align-items: stretch;
property for parent element, remove the height : 100%
from the child element.
Specifying a flex attribute to the container worked for me:
.container {
flex: 0 0 auto;
}
This ensures the height is set and doesn't grow either.
Solution: Remove height: 100%
in .item-inner and add display: flex
in .item
Source: Stackoverflow.com