即使使用了reset.css,也无法删除div之间的额外边距/填充

发布于 2024-12-09 18:10:45 字数 486 浏览 3 评论 0原文

在过去的 1.5 个小时里,我一直在尝试我所知道的一切,但无法解决这个问题。 实际上,据我所知,边距和填充为0,但是,到目前为止,包含的div比包含的图像莫名其妙地宽了4px,高了1px。我不知道那是从哪里来的。

可能导致此问题的原因如下:

  1. 我通过 javascript 将图像的最大宽度和最大高度设置为窗口的大小。
  2. 我正在使用表格、表格单元格和内联块的组合来按照我需要的方式设置版式。
  3. 还以 100% 宽度和高度处理 body 和 html
  4. 这是一个 Tumblr 主题定制(不过从头开始)

代码方面,很难将全部内容放在这里,所以现在我只提供链接。

希望如果能弄清楚这一点,我将能够在这个问题中发布问题代码,以便将来参考。

链接:http://syndex.me

谢谢

I've been trying everything i know for the past 1.5 hours and cannot figure this one out.
Actually far as i can tell, margin and padding are at 0, however, the containing divs are so far, inexplicably 4px wider and 1px taller then the containing image. I don't know where that comes from.

Few things which may be causing this:

  1. I'm setting the max-width and max-height of the images via javascript to the size of the window.
  2. I'm working with a combination of table, table-cell and inline-blocks to set typography in the way i need it.
  3. Also working with body and html at 100% width and height
  4. This is a Tumblr theme customisation (started from scratch though)

Code wise, it's hard to put the entire lot in here, so for now, I'll just give the link.

Hopefully if this can be figured out I'll be able to post the problem code in this question so it's good for reference in the future.

The link: http://syndex.me

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深者入戏 2024-12-16 18:10:45

你是说这个人吗?

.post.photo {
  display: inline-block;
  position: relative;
  height: 100%;
}

您可能不会看到边距,而是会看到文本空白。由于该 div 被定位为内联块,因此它的作用类似于内联元素,例如单词或 标签。如果您删除开始/结束

标记之间的空格,您的“边距”将会神奇地消失。

如果您使用 inline-block 进行定位,line-height: 0font-size: 0 是您最好的朋友;它们关闭了所有有效的空白,尽管它们是非常丑陋的黑客。在大多数情况下,浮动是更好的解决方案。

请参阅 The Fashion Spot 上的 #column_content 和 #column 以查看内联块列在使用中。

You mean on this guy?

.post.photo {
  display: inline-block;
  position: relative;
  height: 100%;
}

You're likely not looking at margin, you're looking at textual whitespace. Since that div is being positioned as inline-block it's acting like an inline element, say, a word or a <strong> tag. If you remove the space between your starting/closing <div> tags, your "margin" will magically disappear.

If you're using inline-block for positioning, line-height: 0 and font-size: 0 are your best friends; they close up any effective whitespace, though they're very ugly hack. Floats are a better solution in most cases.

See #column_content and #column right on The Fashion Spot to see inline-block columns in use.

ζ澈沫 2024-12-16 18:10:45

div 之间有空格,因为您使用 display: inline-block 并且 div 之间由空格分隔。这就像您在不同的行上写字母一样:它们之间会出现一个空格。垂直空白的发生是出于同样的原因——图像显示为内联,并且浏览器为行高保留了一些空间。解决方案是对 div 使用 display: blockfloat: left,对图像使用 display: block

You have spaces between the divs because you use display: inline-block and the divs are separated by white space. It's just like you'd be writing letters on different lines: they'll appear with one white space between them. The vertical white-space happens because of the same reason - images are displayed as inline and the browser reserves some space for the line-height. The solution is to use display: block and float: left for the divs and display: block for the images.

情丝乱 2024-12-16 18:10:45

在这种情况下,我无法使用 float:left 因为似乎没有可靠的方法来使用它来实现居中对齐的一系列 div。答案非常简单,内联阻塞、中心对齐的包装器/子序列中的任何标记之间都不需要有空格,并且应该包装在一行连续的代码中。相当愚蠢,但对于这种情况它 100% 有效。

In this case, i could not use float:left as there seems to be no reliable way to achieve center aligned series of divs using it. The answer is pretty simple, any mark-up within the inline-blocked, center aligned wrapper/child sequence needs to have no white space in between them, and should be wrapped in one continuous line of code. Pretty stupid, but it works 100% for this scenario.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文