Problem <br />In responsive layout, we should be careful with iframe elements. The width and height attributes of the iframe element set its width and height, but when the width or height of the containing block is smaller than the width or height of the iframe, the iframe element will overflow: Such overflowing iframe will destroy the layout of the page. We can find a way to make the iframe element responsive as well, so stay tuned. Workaround In fact, the essence of this method lies in setting the padding-bottom attribute of the iframe-container element. The purpose of setting this attribute is to set the height of the element in disguise. Because setting a percentage for padding-bottom is relative to the width of the parent element. If you set a percentage for the height attribute, it is relative to the height of the parent element. We usually use the default auto for the height value of the parent element, so the height of the child element will also be 0. Therefore, we can only set attributes for padding-bottom. This way, just let the iframe element fill the iframe-container. Copy code The code is as follows:.wrap{ width: 400px; margin: auto; border: 5px solid greenyellow; } .iframe-container{ height: 0; padding-bottom: 97.6%; position: relative; } .iframe-container iframe{ position: absolute; left: 0; top: 0; width: 100%; height: 100%; } @media screen and (max-width: 400px) { .wrap{ width: 300px; } } Copy code The code is as follows:<div class="wrap"> <div class="iframe-container"> <iframe height=498 width=510 src="<a href="http://player.youku.com/embed/XOTE0MjkyODgw">http://player.youku.com/embed/XOTE0MjkyODgw</a>" frameborder=0 allowfullscreen></iframe> </div> </div> The result shows the status: When the viewport width is greater than 400px: When the viewport width is less than 400px: Summary <br />The above is the entire content of this article. I hope that the content of this article can bring certain help to your study or work. If you have any questions, you can leave a message to communicate. |
<<: Example of converting JS one-dimensional array into three-dimensional array
>>: How to quickly return to the top from the bottom when there is too much content on the web page
Many people also asked me what books I read when ...
Download the secure terminal MobaXterm_Personal F...
CSS: Copy code The code is as follows: html,body{ ...
Use of AES encryption Data transmission encryptio...
Stored Functions What is a stored function: It en...
The difference between := and = = Only when setti...
What to do if you forget Windows Server 2008R2 So...
"The great river flows eastward, the waves w...
Purpose: Allow the state data managed in vuex to ...
How can we say that we should avoid 404? The reas...
In the development environment, the vue project i...
Step 1: Ensure that MySQL has binlog enabled show...
When I used g++ to compile the cpp file for the f...
Learn about similar methods for getting character...
1. Basic knowledge (methods of date objects) 😜 ge...