gpt4 book ai didi

javascript - 根据 Android Chrome 上的字体大小调整图像大小

转载 作者:行者123 更新时间:2023-12-04 15:28:59 25 4
gpt4 key购买 nike

我关注 Adjust image size based on the font size根据文本大小更改图像大小,但与 macOS 和 Android(均使用 Chrome)的结果完全不同。

在桌面的 Chrome 上:

enter image description here

在 Android 的 Chrome 上:

enter image description here

可以看到,与文字相比,Android 上的图片要小很多。如何修复,使图像比 Android 上的文本大 2.5?

看起来像是 GitHub 页面的问题?

https://s999inf.github.io/imagezoom/

https://github.com/s999inf/imagezoom/blob/master/index.html

<!DOCTYPE html>
<html>
<head>

<style>
body {
text-rendering: optimizeLegibility;
-webkit-font-smoothing: subpixel-antialiased;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.logos > img {
display: inline-block;
height: 100vh;
max-height: 5em;
}
.test-logos {
display: inline-block;
}
.test-logos__img-2em {
height: 2em;
}
.test-logos__img-3em {
height: 3em;
}
.test-logos__img-5em {
height: 5em;
}
</style>

</head>

<body>
copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text

copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text

copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text


<div class="test-logos">
<img class="test-logos__img-2em" src="https://via.placeholder.com/16x16">
<img class="test-logos__img-3em" src="https://via.placeholder.com/16x16">
<img class="test-logos__img-5em" src="https://via.placeholder.com/16x16">
</div>


<div class="logos">
<img src="https://via.placeholder.com/16x16">
<img src="https://via.placeholder.com/16x16">
<img src="https://via.placeholder.com/16x16">
</div>

</body>

</html>

最佳答案

这是一个实现了建议的解决方案的 CodePen。我已经在浏览器堆栈中对其进行了测试,似乎一切正常。如果您可以提供可能有助于重现错误的代码库或示例的链接。

BrowserStack::Galaxy S5 上的 Chrome

enter image description here

https://codepen.io/uxmfdesign/pen/JjPqBYO

CSS block

.test-logos {
display: inline-block;
}

.test-logos__img-2em {
height: 2em;
}

.test-logos__img-3em {
height: 3em;
}

.test-logos__img-5em {
height: 5em;
}

HTML block
<p>
copy text copy text copy text copy text copy text <img class="test-logos__img-2em" src="https://via.placeholder.com/16x16"> copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text
</p>
<p>
copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text <img class="test-logos__img-3em" src="https://via.placeholder.com/16x16"> copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text
</p>
<p>
copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text <img class="test-logos__img-5em" src="https://via.placeholder.com/16x16"> copy text copy text copy text copy text copy text copy text copy text copy text copy text copy text
</p>
<div class="test-logos">
<img class="test-logos__img-2em" src="https://via.placeholder.com/16x16">
<img class="test-logos__img-3em" src="https://via.placeholder.com/16x16">
<img class="test-logos__img-5em" src="https://via.placeholder.com/16x16">
</div>

我不确定这是否适用于 Android,但在许多情况下,我发现您需要为图像设置基本尺寸并使用最大声明来停止增长。
.logo > img {
height: 100vh;
max-height: 2.5em;
}

另一个问题可能是您没有将图像视为内联 block 。尝试添加
.logo > img {
display: inline-block;
}

关于javascript - 根据 Android Chrome 上的字体大小调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58134358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com