To make the content within an iframe expand in both height and width, use the following method:
- Set within the iframe tag
scrolling="no"和frameborder="0"Disables scroll bars and borders. - Add an element after the `iframe` tag.
<div>And provide this.<div>Set Styleposition: relative; width: 100%; height: 0; padding-bottom: 56.25%;.among,padding-bottomThe value should represent the aspect ratio of the content embedded within the iframe (for example, a video with an aspect ratio of 16:9 should be set topadding-bottom: 56.25%)。 - Use absolute positioning as mentioned above.
<div>Place a child element inside and set its style to:position: absolute; top: 0; left: 0; width: 100%; height: 100%;。
The complete code example is shown below:
<div style="position: relative; width: 100%; height: 0; padding-bottom: 56.25%;">
<iframe src="https://example.com" frameborder="0" scrolling="no"></iframe>
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></div>
</div>