Hi!
How can i float my list-items like so: http://cl.ly/77c44596c0cdff8d77d5
Thanks in advance
ul {
list-style: none;
overflow: hidden;
}
ul li {
width: 200px;
height: 50px;
margin-right: 15px;
float: left;
}
Although note that with this you will get the li
s in this order:
1 2 3
4 5 6
Edit:
Well that's slightly more difficult. If you can live with the lack of browser support you can use the CSS3 column property.
Pretty easily by floating them within their <ul>
. The width set on the ul is to set them up in the same grid pattern as your screenshot.
ul {
width: 330px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
float: left;
margin: 5px;
width: 100px;
height: 100px;
background: red;
}
In action here.
Here's an example that uses negative margins:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<style type="text/css">
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul li {
margin: 5px;
height: 100px;
width: 100px;
background: red;
float: left;
}
ul li.negMarg {
margin-top: 120px;
margin-left: -106px;
background: blue;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li class="negMarg">2</li>
<li>3</li>
<li class="negMarg">4</li>
<li>5</li>
<li class="negMarg">6</li>
</ul>
</body>
</html>
If you don't mind javascript you could use the jQuery :nth-child Selector. The link contains a nice example of a situation similar to yours.