tags:

views:

92

answers:

4

Here's a picture of my current situation : alt text But I don't want the images below each other, I want them in a line, a straight horizontal line. This is the code I have currently:

<span title="Milestones" class="tl-icon">
<span class="tl-msg">
<span class="tl-msg-inside">
<div class="slice1"></div>
<div class="slice2"></div>
<div class="slice3"></div>
<div class="slice4"></div>
<div class="slice5"></div>
<div class="slice6"></div>
<div class="slice7"></div>
<div class="slice8"></div>
<div class="slice9"></div>
<div class="slice10"></div>
<div class="slice11"></div>
</span>

So how would I make all the images be in a straight line?

+1  A: 

You should set the class for all the divs to the same class, something like slices, and then go with:

 .slices {
     display: inline; 
 }
Anthony
You can't have `width` and `height` on an `inline` element, and therefore, the images wouldn't display fully.
Justin Johnson
Actually, I'd opt for `inline-block`, but IE get's fussy with it. I think floating would work best, but I try avoid it. Would the divs flatten if they were inline?
Anthony
+6  A: 

Try floating the images to the left. For example:

.image {
    float: left;
}
Alan Haggai Alavi
+1, but there's no class named 'image'. span.tl-msg-inside div { float:left; } would work on the markup above.
codeinthehole
Yup. And `clear` might be needed after all of that too.
Justin Johnson
@codeinthehole That almost completely works, except in one place where there is a gap (http://grab.by/GQm). I've checked that it's got no padding nor any margin. Why is this?
Joshua
Fixed it! Thanks!!!
Joshua
+1  A: 

DIVs are block level elements and will cause each slice to be on it's own line. You can either change the display property of those divs to be inline, or use SPANs instead.

Logan5
-1 You can't have width and height on an inline element, which is required to display the images as backgrounds as he seems to be doing.
Justin Johnson
A: 

There's solutions to your problem, and then there's solutions to your problem.

The immediate fixup is to make the divs display:inline or float:left. Divs are naturally block which means each one will fill the entire width of their container, so they stack below each other. Inline makes them act like text and shrink to the size of their content, and sit next to each other. Floating works more-or-less similarly.

The better fixup is to avoid those divs altogether. Can you just use <img>? That's usually ideal.

Xanthir
You cannot display inline and maintain the width and height attributes. Also, why avoid `divs`?
Justin Johnson
Indeed, but it's not apparent from the OP whether or not that's necessary. If that's the case, display:inline-block would work, and float:left will as well. I recommended to avoid divs because it appears very likely that they're completely unnecessary, and the OP is just suffering from divitis. Use the tool most appropriate for the job - if you're putting images on your page, that tool is almost always the img element.
Xanthir
img is the semantically appropriate tag if and only if the image is part of the content. If it is part of the layout, or a background, then it is not. Also, inline-block is not completely supported in IE 6/7: http://www.quirksmode.org/css/display.html
Justin Johnson
Sorry, Justin Johnson, you're wrong. <img> is appropriate anytime you want to, you know, put an image in your page. (Of course if it's meant to be a background you should put it as a background, but if you're putting an empty element in your page solely to host a background so you can avoid <img>, you're doing it wrong.) If it's purely for decorative purposes, you give it an empty alt attribute to indicate that. Additional benefit: <img> acts like an inline-block in the old IEs.
Xanthir