为什么我的某些表格单元格的内边距比其他单元格多?
我在这里制作了一个整洁的小照片库 - http://schnell.dreamhosters.com/wallpapers.php< /a>
如果您愿意,请随意环顾四周并拍摄一些壁纸,这就是它的用途。
无论如何,我遇到的问题是,如果您仔细观察这些列,就会发现第一个和最后一个列的填充量与中间的填充量不同。这是此页面的相关 CSS...
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;
}
我没有在标记中添加任何填充,并且添加填充的唯一 CSS 样式是针对 td 标签的,所以我很困惑为什么中心列的填充比外层的。我尝试取消填充类,认为可能带有链接的单元格使单元格增长,使得带有图像的单元格需要更多填充,但这不起作用。
抱歉,如果这看起来有点微不足道,但在视觉效果方面,有时在代码方面,我往往是相当强迫症和完美主义者。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
960 像素 / 5 个单元 = 每个单元 192 像素
有 10px 的水平内边距。
每个表格单元格有 4 像素未计算(总共 20 像素)。
因此,如果将 #gallery 宽度减小到 940px,浏览器将不会有额外的宽度来决定如何处理。
960px / 5cells = 192px per cell
has 10px of horizaontal padding.
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.
造成额外空白的不是表格单元格填充。这就是表格的 960 像素宽度在这些列之间的划分方式。尝试为每列指定相同的宽度,同时为边框分配几个像素。
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.
快速查看你的 html,我可以发现这不是填充的不同。尝试为所有列设置宽度并从表格中删除宽度。
试试这个:
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:
将表格的宽度从 960px 更改为更小的值...我尝试了 930px,所有填充看起来都一样。
您必须计算:图像宽度 = 176,5 个图像等于 880,填充为 50(总计),边框为 6...总共 936。将表格设置为 936px 宽。
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.