Question

I have 3 DIVs within a DIV. The boxes will have an image. Currently they are image placeholders for future.

I would like to use display: inline-block; to line them up on the same line. For some reason they are still vertical instead of horizontal. I do not want to use float as I feel float should be used elsewhere.

HTML:

<div class="quickboxes">
  <div id="box1"><img name="" src="" width="75" height="75" alt="">1</div>
  <div id="box2"><img name="" src="" width="75" height="75" alt="">2</div>
  <div id="box3"><img name="" src="" width="75" height="75" alt="">3</div>
</div>

CSS:

.quickboxes {
    display: inline-block;
}

#box1 {
    width: auto;
}

#box2 {
    width: auto;
}

#box3 {
    width: auto;
}
Was it helpful?

Solution

display:inline-block; needs to be in the css for the image divs, not the containing div.

OTHER TIPS

Add the rule:

#box1, #box2,#box3 {
display:inline-block;
}

jsFiddle example

In order for the boxes to be in row, you also have to set the inline-block property on them, not just the parent container (which you probably don't need anyway).

An alternate way to avoid using inline-block is to use floats. Float them to the left and clear the floats in each divs.

It would be better if you include inline-block in both as shown:

.quickboxes {
    display: inline-block;
}
#box1, #box2,#box3 {
display:inline-block;
}

And to center these boxes

.quickboxes {
    display: inline-block;
position: relative;
left: -50%; /*- is important for outer div*/
}
#box1,#boc2,#box3{
display: inline-block;
position: relative;
left: 50%; /* + is important for inner div*/
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top