views:

76

answers:

4

So I made a neat little photo gallery here at - http://schnell.dreamhosters.com/wallpapers.php

Feel free to look around and take some of the wallpapers if you like, that's what it's there for.

Anyways, the problem I'm having is that if you look very closely at the columns, the first and last ones have different amounts of padding from the ones in the middle. Here's the relevant CSS for this page...

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    background: transparent;
}
a:visited   {
    color: blue;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* remember to define focus styles! */
:focus {
    outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
    text-decoration: none;
}
del {
    text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
    border: solid 1px black;
    border-collapse: collapse;
    border-spacing: 0;
}

td  {
    border: solid 1px black;
    padding: 5px;
    text-align: center;
}

#gallery    {
    margin: 10px auto;
    width: 960px;
}

#fancybox-title {
    font-size: 1.2em !important;
    font-weight: bold !important;
}

.nav    {
    font-weight: bold;
    font-size: 1.1em;
    text-decoration: none;
}

.padding    {
    padding: 0 0.75em;
}

I don't add any padding in the markup and the only CSS styling that adds padding is for td tags, so I'm confused as to why the center columns are getting more padding than the outer ones. I've tried taking away the padding class thinking maybe the cells with the links are making the cells grow such that the cells with images need more padding, but that didn't work.

Sorry if this seems a bit insignificant, but I tend to be rather OCD and perfectionist when it comes to visuals and sometimes with code also.

+1  A: 

Quickly looking at your html, I can see that it's not the padding that is different. Try putting a width to all the column and remove the width from the table.

Try this:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    background: transparent;
}
a:visited    {
    color: blue;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* remember to define focus styles! */
:focus {
    outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
    text-decoration: none;
}
del {
    text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
    border: solid 1px black;
    border-collapse: collapse;
    border-spacing: 0;
}

td    {
    border: solid 1px black;
    padding: 5px;
    text-align: center;
    width:200px;
}

#gallery    {
    margin: 10px auto;
}

#fancybox-title    {
    font-size: 1.2em !important;
    font-weight: bold !important;
}

.nav    {
    font-weight: bold;
    font-size: 1.1em;
    text-decoration: none;
}

.padding    {
    padding: 0 0.75em;
}
Dan
Assuming this doesn't screw with the tds that have colspans > 1, I think I'll go with this method in the future, though instead of declaring it in the external stylesheet, I'd generate it dynamically with PHP such that the td widths add up to a nice number like 960. Or I may also generate the entire table's width on the fly instead.
Mathias Schnell
+1  A: 

Change the width of the table from 960px to a smaller value... I tried 930px and all paddings look the same.

You have to calculate: image width = 176, 5 images make 880, paddings are 50 (total), borders are 6... all together 936. Set the table to be 936px wide.

Šime Vidas
Yeah, I have PHP on the backend calculating the width of the thumbnails on the fly. I guess I miscalculated and forgot to account for some things.
Mathias Schnell
+3  A: 

It's not the table cell padding that's causing the extra white space. It's how the 960 pixels width of your table is divided up between those columns. Try specifying the same width for each column, while accounting a few pixels for the border.

KatieK
That did it. I changed the width to 900px and the extra padding is now gone. Funny too, cause I had believed all this time that I was overshooting the 960px mark, but I guess not.
Mathias Schnell
+3  A: 

960px / 5cells = 192px per cell

  • Each image is 176px wide.
  • Each cell has 10px of horizaontal padding.
  • Each cell has a 1px border (x2)
  • 188px per cell.

There is 4px unaccounted for per table cell (20px total).

So if you reduce the #gallery width to 940px, there will be no extra width for the browser to decide what to do with.

simplemotives
The cell borders collapse. The total width of all borders is 6px, not 10px. The table width should be set to 936px.
Šime Vidas
Thanks, I think I had miscalculated something somewhere or I expected that basing everything off of 960 in my calculations would result in a net width of 960, but since I have to floor some fractions I guess that was not going to happen. Taking padding, borders and number of columns into account I should be able to dynamically figure out the exact table width needed through PHP.
Mathias Schnell