tags:

views:

42

answers:

5

I have:

#content { width: 100%;text-align:center; }
.item { float:left;}

And then

...

<div id="content">
    <div class="item"><img /><br />wordsn</div>
    <div class="item"><img /><br />stuff</div>
    <div class="item"><img /><br />asdasdasdn</div>
    <div class="item"><img /><br />Dhdfrhwon</div>
    <div class="item"><img /><br />sewfafdion</div>
</div>

...

I want to center these images items in the div, and have them float next to eachother, and have it wrap nicely. Not working.

I have tried everything and it works in IE and breaks in Firefox so I hack some more crap and then it breaks in IE. I am PHP need CSS.

+1  A: 
.item { width: 400px; margin: auto 0; }

You need to specify a width so it can calculate the appropriate margins.

Aren
this works with a fixed width only. Often impractical.
Pekka
this almost works but broken in IE
Mohamed Ikal Al-Jabir
You still floating? It should work fine in I.E.
Aren
A: 

Get rid of float and start using display: inline for the item divs.

Then you can give content a text-align: center - should work.

By the way, semantically, a structure like this might work better - depending on what those divs represent, of course.

<ul id="content">
    <li><img />wordsn</li>
    <li><img />stuff</li>
    <li><img />asdasdasdn</li>
    <li><img />Dhdfrhwon</li>
    <li><img />sewfafdion</li>
</ul>
Pekka
this solution does not work even tho it seems like it should. I tried inline-block (which is closer to what is needed) and such which IE doesn't work. This is a very tricky problem I have tried many things.
Mohamed Ikal Al-Jabir
@Mohamed then I don't understand your question completely - I'm using this method all over and it works fine. What exactly doesn't work?
Pekka
I want many per row this is only giving only 1 or not centering depending on how I mix up
Mohamed Ikal Al-Jabir
@Mohamed sorry, I overlooked the `<br>` s. Get rid of them and it will work.
Pekka
I mean it is not working across browsers too, I think if can make inline-block in IE6 will work
Mohamed Ikal Al-Jabir
@Mohamed why doesn't plain `inline` work for you?
Pekka
I have solved problem will post solution
Mohamed Ikal Al-Jabir
the plain inline was not working in some older browsers and even newer for wierd reason
Mohamed Ikal Al-Jabir
@Mohamed I think that is solvable but anyway, you seem to have a working solution so it's fine.
Pekka
A: 

Is this the kind of thing you are trying to achieve? (you will need to resize the page to see the wrap effect)

djgdesign.co.uk

Chief17
those are aligned left
Mohamed Ikal Al-Jabir
Ah sorry, didn't read that part of your question properly
Chief17
A: 

Okay this is what I got to work across all browsers:

#content {
text-align:center;
}

.item {
     display: -moz-inline-box;
    display:inline-block;
}

* html .item { display:inline; }  /* for IE 6? */
* + html .item { display:inline; }  /* for IE 7? */

edit: width not required

Mohamed Ikal Al-Jabir
I still think this could be solved using a simple `display: inline` for all browsers - if the items don't have to have a fixed width. But if this works for you in all browsers, all right!
Pekka
wait no, width required for IE6. god damn.
Mohamed Ikal Al-Jabir
A: 

content .item{width:200px;margin:0 auto}

quinti