I have thumbnails in a div… the thumbnails are generated dynamically, every page has a diff no. of thumbnails… and b/c of resp design the width of the div (and thus the no. of tn’s per row) will vary… I need to:
“saran-wrap” this div around tn’s – and have it still be centered inside main wrapper div…
center tn’s inside div so that when at bottom row of tn’s there are, say, only three tn’s (as opposed to the rest, which have each, say, six tn’s) then I would like these three tn’s in bottom row to be centered, not on the left… I had to float-left the tn’s, so they’re positioned side by side…
#photoThumbs a {height:50px; width:50px; display:block; float:left; margin:0 2px 4px 2px; } #photoThumbs a img {height:100%; width:100%; /* do not want to do bg-img for resp design…*/ }
display: inline-block is perfect for that. Center the container with margin: 0 auto and set the container to text-align: center. Give that a try and see how you go. Make up a proper demo, too, so we can help further. Post full page code here or make up a pen at CodePen.
You could try giving the container display: table instead, perhaps with a max-width to stop it expanding too much. Not sure how it will play with inline-block children, though. An interesting experiment. I look forward to a demo!
Ditto Ralph’s suggestion. Here are three methods of coding the list items.
(1) conventional - which requires an additional line of CSS (shown).
(2) and (3) - different ways to ‘chain tags’. Fool proof older techniques.
I fancied-up the coloring of the anchor border around the thumbs a tad.
Note that the way you specified the images to be sized, the rendered proportions will be 1x1, which means the image could be distorted if the original is not square.
Thanks for the feedback, maya90. Glad it’s helpful.
{display:table} is a great property to have in your ‘toolbox’
BTW - the reason for the extra line of CSS in the ‘conventional’ list tag arrangement, the comment marks in the second example and the shifted and abutted <li> tags in the third example, is to eliminate the white space that normally exists between inline or inline-block objects and inline list items. That white space is sometimes undesirable because it (1) adds space between and below the items, and (2) that white space is affected by the font-size of the <ul> (not the <li>s). So, to obtain maximum control over the spacing around the list items (or other inline-block objects), many coders take steps to eliminate that white space (as shown in these examples).
[FONT=Verdana]just one question, ronpat… this "display:table thingie works on all mobile devices? (it works everywhere except IE, right? (gee, what a surprise…
thanks again, that worked wonders, it’s exactly what I wanted…
yes I know about the white space in those situations, especially FF handles whitespace in those situations poorly (happens with <td>'s also…)
[/FONT]
I can’t vouch for mobile devices, but the {display:table} properties work in IE8+ on the desktop (you didn’t mention which version of IE you were referring to).
I’m not aware of a situation where FF does not handle the space between HTML <td> tags correctly. If you can post a working example, I’ll be glad to give it a look. It might be something simple