html - HTML 调整 iFrame 内容的大小
问题描述
我目前正在使用 sendgrid 的 prebuildt 电子邮件形式作为 iFrame。
一切都按预期工作。我唯一的问题是在移动设备上 iFrame 的内容太大而无法显示在屏幕上,如您在图像上看到的那样:
因此,我尝试使用scale: 0.5调整内容的大小,但这只会使整个 iFrame 变小。
我当前的 CSS 代码如下:
.bg-modal {
width: 100%;
height: 100%;
position: fixed;
top: 0;
justify-content: center;
align-items: center;
}
.modal-contents {
height: 600px;
width: 600px;
background-color: white;
text-align: center;
position: relative;
border-radius: 4px;
}
.iframeClass{
width: 100%;
height:100%;
overflow:hidden;
}
我的 HTML 是这样的:
<div class="bg-modal">
<div class="modal-contents">
<iframe scrolling="no" class="iframeClass" frameborder="0" src="https://..."></iframe>
</div>
</div>
我不想显示滚动条。
有人知道这个响应问题的解决方案吗?
解决方案
您的设备分辨率低于 600 像素,因此它会横向滚动。
你可以用max-width
它来解决它。
解决方案
.bg-modal {
width: 100%;
height: 100%;
position: fixed;
top: 0;
justify-content: center;
align-items: center;
}
.modal-contents {
height: 600px;
width: 600px;
max-width: 100%; /* This makes it so if the device is under 600px, it will resize to be the width of the screen and it will not overflow */
background-color: white;
text-align: center;
position: relative;
border-radius: 4px;
}
.iframeClass{
width: 100%;
height:100%;
overflow:hidden;
}
如果您仍然遇到问题,请尝试以下操作:
body {
overflow-x: hidden;
}
推荐阅读
- node.js - node js app.use 抛出一个中间件函数
- java - 在两个线程中交替打印字符串
- python - SyntaxError:yt 模块的语法无效
- r - 将线性回归与对数线性回归与 R 进行比较
- c# - C#/PHP 如何构建不能被滥用的 API
- python - Mathematica 的 NDSolve 和 SciPy 的 solve_ivp 返回不同的结果
- html - 网格中的多个按钮
- node.js - Node.js strApi 连接到谷歌云
- c++ - 如何创建一个行为几乎与 int64_t 完全相同的类型安全句柄,但不允许句柄类型之间的隐式转换?
- webrtc - webRTC 直播 Nativescript