Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating HTML list items with different height

I want to float my list items into a grid like structure depending on the available width.

Unfortunately my items are of different hight and sometimes the items don't wrap all the way to the left. In the example I made the first item a little higher to show the problem, in reality I have no idea which item will be which height.

How can I make the 2nd row start a little further down, but always on the left side ?

<html>
<head>
<style>
li {display: block; width:200px; height:100px; float:left; border:1px solid;}
</style>
</head>
<body>
<ul>
<li style="height:110px;"></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
like image 826
Gene Vincent Avatar asked Sep 13 '13 14:09

Gene Vincent


1 Answers

Use display: inline-block instead of float: left/right

jsFiddle Demo

Further reading: What’s the Deal With Display: Inline-Block?

like image 183
Itay Avatar answered Sep 22 '22 03:09

Itay