0

I have a section that contains 6 articles. I have sized these article boxes to fit the screen of an iPhone. If the computer screen is large enough I want them to line up side by side like this;

######

But as the screen gets smaller I want them to drop to the line bellow but be centered in the page like these:

#####
  #

####
 ##

###
###

##
##
##

#
#
#
#
#
#

I would prefer an only CSS method to do this, but if there isn't one I will try others. I have searched this site the web and several books and I have not been able to find a way to do this.

Stickers
  • 75,527
  • 23
  • 147
  • 186
sjtwiv
  • 177
  • 1
  • 10

2 Answers2

1

You could set text-align:center to the container, and display:inline-block to the item.

JsFiddle Demo

.wrap {
    text-align: center;
}
.item {
    display: inline-block;
}
<div class="wrap">
    <div class="item">item</div>
    <div class="item">item</div>
    <div class="item">item</div>
    <div class="item">item</div>
    <div class="item">item</div>
    <div class="item">item</div>
</div>

Further reading - How to remove the space between inline-block elements?

Community
  • 1
  • 1
Stickers
  • 75,527
  • 23
  • 147
  • 186
  • This worked though I did have to remove the spacing between the article elements so there borders would collapse. Other than that it works like a charm thanks. – sjtwiv Jun 24 '15 at 16:15
  • 1
    @sjtwiv The white spacing thing is very common with inline elements, you can follow the link above to read more, my favorite solution is using `font-size` tricks. Other than that, `box-sizing:border-box` can be very useful too. – Stickers Jun 24 '15 at 16:18
-2

You should look into using a framework, if anything to make everything cross-browser happy. Most frameworks have such a responsive design layout system to do exactly what you need.

My favorite is the Twitter Bootstrap: http://getbootstrap.com/

w3schools also has a lightweight framework you might like if you want more control: http://www.w3schools.com/w3css/default.asp

good luck

Snappawapa
  • 1,697
  • 3
  • 20
  • 42