Reputation: 33
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;
}
Upvotes: 0
Views: 2132
Reputation: 85653
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*/
}
Upvotes: 0
Reputation: 193
An alternate way to avoid using inline-block
is to use floats.
Float them to the left and clear the floats in each div
s.
Upvotes: 1
Reputation: 208030
Add the rule:
#box1, #box2,#box3 {
display:inline-block;
}
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).
Upvotes: 1
Reputation: 417
display:inline-block; needs to be in the css for the image divs, not the containing div.
Upvotes: 1