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
This article mainly introduces the installation/st...
There are many Hadoop installation tutorials on L...
There are two files a.htm and b.htm. In the same d...
Table of contents 1. Operators Summarize 1. Opera...
As the application of centos on the server side b...
Code example: public class JDBCDemo3 { public sta...
When learning kubernetes, we need to practice in ...
Table of contents Official introduction to Node.j...
Writing a Dockerfile Taking the directory automat...
{ {}} Get the value, the original content of the ...
one. Preface <br />You will see this kind of...
The latest download and installation tutorial of ...
Classical color combinations convey power and auth...
This article example shares the specific code of ...
Need to export the fields and properties of the t...