Center more than 3 images evenly in CSS?

Soldato
Joined
27 Mar 2004
Posts
6,693
Location
Devon
Hi there,

I'm having a problem spacing multiple images in a horizontal line evenly.
www.gameordie.co.uk is the site. The images are at the bottom. I would like to spread them evenly across the width of the site. Google doesn't really seem to be giving my and real answers.
 
Associate
Joined
16 Mar 2013
Posts
396
Can't see anything?

Best way is to put them in a div. Give the div the width you want the spread to be across.

Give each image the same class of image or whatever.

Float them left, width of say 28%. That leaves 16% for margin. Margin-left of 4% and they'll be across all nicey nicey as the last right margin will be the remaing 4%. Be sure to use box-sizing:border-box as you're working to 100% widths. Can get tricky otherwise in IE. padding and border set to 0 and none.

There was something I was reading the other day about using justify but I think it was for menu items rather then images.

The above is how I do image, don't think I missed anything.
 
Soldato
OP
Joined
27 Mar 2004
Posts
6,693
Location
Devon
text-align:center;

padding-left:30px;
padding-right:30px;

This seemed to do it quite easily. I wanted it so I could just change the icons when I wanted without really having to mess around with dimensions.
 
Associate
Joined
16 Mar 2013
Posts
396
text-align:center;

padding-left:30px;
padding-right:30px;

This seemed to do it quite easily. I wanted it so I could just change the icons when I wanted without really having to mess around with dimensions.

That work did it? It can be a bit hit and miss sometimes using things like text-align and line-height to get things centered.

If you wanted to make it so that the images were A) responsive to viewport and B) responsive to what images you used, you could use jquery to dynamically alter the height of the images while scaling the width, adjusting margins and centering them.

May be a little overkill perhaps? :p
 
Soldato
OP
Joined
27 Mar 2004
Posts
6,693
Location
Devon
Haha a little over kill. The sites a project just to keep me sane through uni and to try and get a more adult gaming community together. It will probably really just be a splash page and possibly some forums. But I wanted something for now so I can have some Twitch streams and Youtube videos up and a domain. But looks ok to me for the moment. Just need to design my own background and logo now. Thanks for the ideas though people. Slowly learning CSS.
 
Associate
Joined
16 Mar 2013
Posts
396
CodeAcademy is good as well. I came across Treehouse first so that's the one I went with and don't have the time to be on another learning site, don't have enough time to be on Treehouse genning up these days.

I'll agree with using JS to do something that you should use CSS as being a hack but it's very useful if you want margins and sizing and positioning that changes depending on viewport size and size of the image.
 
Back
Top Bottom