表格有 1 像素的不需要的填充
由于某种原因,我在桌子上得到了 1px 的填充或边框。我不知道如何摆脱它。我尝试将 display:block;margin:0;padding:0;
添加到图像中,但这并不能解决问题。我还在 CSS 中尝试过 和
border:none;
。对于我的一生,我无法弄清楚这一点。
这是一个问题的原因是因为我试图让图像与 tr 两侧的边缘对齐,为其提供圆形边框,因为 CSS3 border-radius 不适用于 TR。我已将 table, table * {border:1px Solid red;}
添加到 CSS 中,从这一点来看,它肯定看起来像是填充或边距问题。
问题出在这张图片中:
在左侧和右侧,您可以看到图像和边缘之间有某种填充或其他东西表的。红色边框就是为了看到这一点而存在的。
这是我的 CSS:
table a {
color: #f7941E;
font-family: Arial;
font-size: 16px;
font-weight: bold;
/* css3 */
transition: color .25s;
-khtml-transition: color .25s;
-moz-transition: color .25s;
-o-transition: color .25s;
-webkit-transition: color .25s;
}
table a:hover {
color: #f8ae57;
}
table {
width: 610px;
}
table tr {
height: 33px;
padding: 0;
margin: 0;
vertical-align: middle;
}
table td {
border-collapse: collapse;
}
table tr.head {
color: #58585a;
font-family: Rockwell, serif;
font-size: 18px;
font-weight: bold;
text-transform: lowercase;
}
table tr.even {
background: #EEE;
height: 33px;
}
table tr td img {
padding: 0 15px 0 13px;
vertical-align: middle;
}
table tr td a img {
opacity: .6;
/* css3 */
transition: opacity .25s;
-khtml-transition: opacity .25s;
-moz-transition: opacity .25s;
-o-transition: opacity .25s;
-webkit-transition: opacity .25s;
}
table tr td a img:hover {
opacity: 1;
}
和 HTML:
<table border="0">
<tr>
<td><img src="images/tr-left.png" style="display:block;margin:0;padding:0;">
<td><img src="images/some-icon.png" /> <a href="#">Some Content</a></td>
<td><img src="images/tr-right.png" style="display:block;margin:0;padding:0;">
</td>
</table>
For some reason I'm getting a 1px padding or border on a table. I can't figure out how to get rid of it. I've tried adding display:block;margin:0;padding:0;
to the images, but that doesn't solve it. I've also tried <table border="0">
and border:none;
in the CSS. For the life of me I can't figure this out.
The reason it's a problem is because I'm trying to get images to line up with the edges on both sides of a tr, to give it rounded borders, since CSS3 border-radius doesn't work on TR's. I've added table, table * {border:1px solid red;}
to the CSS, and from that, it definitely looks like a padding or margin issue.
The issue is in this image:
on the left and right sides, you can see there's some kind of padding or something between the images and the edge of the table. The red borders are there just to see this.
Here's my CSS:
table a {
color: #f7941E;
font-family: Arial;
font-size: 16px;
font-weight: bold;
/* css3 */
transition: color .25s;
-khtml-transition: color .25s;
-moz-transition: color .25s;
-o-transition: color .25s;
-webkit-transition: color .25s;
}
table a:hover {
color: #f8ae57;
}
table {
width: 610px;
}
table tr {
height: 33px;
padding: 0;
margin: 0;
vertical-align: middle;
}
table td {
border-collapse: collapse;
}
table tr.head {
color: #58585a;
font-family: Rockwell, serif;
font-size: 18px;
font-weight: bold;
text-transform: lowercase;
}
table tr.even {
background: #EEE;
height: 33px;
}
table tr td img {
padding: 0 15px 0 13px;
vertical-align: middle;
}
table tr td a img {
opacity: .6;
/* css3 */
transition: opacity .25s;
-khtml-transition: opacity .25s;
-moz-transition: opacity .25s;
-o-transition: opacity .25s;
-webkit-transition: opacity .25s;
}
table tr td a img:hover {
opacity: 1;
}
And the HTML:
<table border="0">
<tr>
<td><img src="images/tr-left.png" style="display:block;margin:0;padding:0;">
<td><img src="images/some-icon.png" /> <a href="#">Some Content</a></td>
<td><img src="images/tr-right.png" style="display:block;margin:0;padding:0;">
</td>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
<table border="0" cellpadding="0" cellspacing="0">
这似乎为我解决了问题。
CSS:
This seemed to fix things for me.
CSS:
我的问题是一些奇怪的行为,我已经尝试了书中的所有技巧,但是填充很顽固。最后我发现,为
body
元素设置的line-height
属性,正在创建以下效果:顶部填充
。在使用本地化规则覆盖line-height: normal;
后...问题得到了解决。
My issue was some weird behavior, and I had tried all the tricks in the book, but that padding was stubborn. Finally I found out, that the
line-height
attribute set for thebody
element, was creating the effect ofpadding-top
. After overriding which, with a localized rule, ofline-height: normal;
...the problem got solved.