简体   繁体   English

当不同的窗口大小时,img 标签似乎给出了空白

[英]img tag seems to give white space when different window sizes

For some reason png/jpg/svg files that I put into my img tag give at some random sizes a whitespace.出于某种原因,我放入 img 标签中的 png/jpg/svg 文件会以一些随机大小给出一个空格。 Here is a link with a GIF: https://gyazo.com/0cbbe95f7c9ca4e6e504448cacd8ea2c这是一个带有 GIF 的链接: https : //gyazo.com/0cbbe95f7c9ca4e6e504448cacd8ea2c

In the GIF im resizing the screen with Chrome its developer tools -> device toolbar.在 GIF 中,我使用 Chrome 的开发者工具 -> 设备工具栏调整屏幕大小。 Also if I click Ipad or some other device I see a white line.此外,如果我单击 Ipad 或其他设备,我会看到一条白线。 Its not on all devices but only on some.它不是在所有设备上,而是在某些设备上。 If I change image or check one of my other images I have the same white line but on different devices/sizes.如果我更改图像或检查我的其他图像之一,我有相同的白线,但在不同的设备/尺寸上。 Why does this happen?为什么会发生这种情况?

What I checked/tried我检查/尝试过的

My image tag has the display: block;我的图像标签显示:块;
width/height: 100%;宽度/高度:100%;
margin/padding: 0px;边距/填充:0px; Which it could never be since the whiteline is quite random.这是不可能的,因为白线是非常随机的。
object-fit/background-size: cover, contain, fill, everything basicly; object-fit/background-size:覆盖,包含,填充,基本上所有的东西;
overflow: hidden;溢出:隐藏;
vertical align: top, bottom;垂直对齐:顶部,底部;
div tag around my img and div tag.我的 img 和 div 标签周围的 div 标签。

Nothing here worked.这里没有任何工作。

Is it possible that Chrome its device tool thingy is just not working correcty? Chrome 的设备工具可能无法正常工作吗? I have some experience with it on different projects that I had to refresh the complete toolbar or switch between device to make it look normal or to make some code I added in the tools working.我在不同的项目上有一些经验,我不得不刷新完整的工具栏或在设备之间切换以使其看起来正常或使我在工具中添加的一些代码工作。 In the current case it doesn't fix it but maybe there are some other known issues?在当前情况下,它没有修复它,但也许还有其他一些已知问题?

This is my code这是我的代码

HTML: HTML:

<img src="./images/yellow-top.png" alt="top"> <!-- Shows white space at random sizes -->
<div class="bg-yellow"> <!-- height based on its content. Around 800px in my case -->
           ...
</div>
<img src="./images/yellow-bottom.png" alt="bottom"> <!-- Shows white space at random sizes -->

CSS CSS

img {
   display: block;
   width: 100%;
}

Why does it do this and how can I fix this?为什么会这样,我该如何解决?

Developer tools was zoomed in at something else then 100%.开发人员工具被放大到其他地方,然后 100%。 This way it shows a small whitespace below an image.这样它会在图像下方显示一个小空白。 Setting it back to 100% fixed it.将其设置回 100% 修复了它。 SVG file still gives me an whitespace. SVG 文件仍然给我一个空格。 This is probably something within SVG files.这可能是 SVG 文件中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM