tags:

views:

506

answers:

6
Q: 

float divs

I have a list with two <div>s in every <li> and I want to float them one next to the other and I want the <li> to take the whole availabe space. How do I do it?

<html>
<head>
<title></title>
<style type="text/css">
body {
}
ul {
}
li {
}
.a {
}
.b {
}
</style>
</head>
<body>
<ul>
<li>
<div class="a">
content
</div>
<div class="b">
content
</div>
</li>
</ul>
</body>
</html>
A: 
li{width:100%;}
.a{}
.b{float: left;}

That should do as required from my knowledge of CSS

workmad3
A: 

Without checking to make sure, this should work


LI { width: 100%; }
.a { float: left; }
.b { float: right; }
Jeremiah Peschka
+2  A: 
 *{ margin: 0; padding: 0;}
 li{  width: 100%: display: block; } 
 li:after{ clear: both; } 
 div.a{ width: 49%;  float: left; }
 div.b{ width: 49%;  float: left; }

Should do the trick.

Kent Fredric
+2  A: 

For the divs, you just need to float left and the li, you want to do a clear. So:

li
{
    clear: left;
}
.a
{
    float: left;
}
.b
{
    float: left;
}
AdamB
You have to specify a width on floated elements otherwise you won't get the 2-column effect you're after. 49.9% or something should do it.
sanchothefat
A: 

li { width: 100%;}

.a { float: left;}

.b { float: left;}

Bloodhound
A: 

I assume by take the whole space you mean a width of 100%. I would also assume that you do not want styling applied to the list, which is why I have removed it in this example. This is also hack-free. You need not clear anything, so long as your list item has a width and the overflow: hidden property/value pair.

ul,
li {
    width: 100%;
    list-style-type: none;
    margin: 0;
    padding: 0;
}
li {
    overflow: hidden;
}
li div.a,
li div.b {
    float: left;
}
hal10001