I set my UL items to have display: inline-block
, 30% width, and they align side by side corretly.
But, they vertical align to bottom if there is a bigger li.
Is there any way to top align this items?
One solution that I don't like is to have a Javascript that equals height from all elements, but don't seens to be a clean solution to this problem, since different rows may need different heights.
Code snippet here..
ul {
display: block;
width: 100%;
list-style: none;
padding: 0;
}
ul > li {
display: inline-block;
width: 50%;
}
<ul>
<li>
<h1>Item A with Long text</h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam quisquam debitis officia impedit sed omnis dolorem nihil doloribus dolore provident totam unde minus possimus quae dignissimos quo necessitatibus ipsa molestias.
</li>
<li>
<h1>Item B with Short Text</h1>
</li>
<li>
<h1>Item C with Short Text</h1>
</li>
<li>
<h1>Item D with Short Text</h1>
</li>
</ul>
This is also related to the famous white space bug.
See this demo with the fix using font size https://jsfiddle.net/8hfgmwLy/2/
HTML
<ul>
<li>
<h1>Item A with Long text</h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam quisquam debitis officia impedit sed omnis dolorem nihil doloribus dolore provident totam unde minus possimus quae dignissimos quo necessitatibus ipsa molestias.
</li>
<li>
<h1>Item B with Short Text</h1>
</li>
<li>
<h1>Item C with Short Text</h1>
</li>
<li>
<h1>Item D with Short Text</h1>
</li>
</ul>
CSS
ul {
display: block;
width: 100%;
list-style: none;
padding: 0;
margin: 0;
font-size: 0;
}
ul > li {
display: inline-block;
width: 25%;
background: grey;
vertical-align: top;
font-size: 14px;
}