How To Create Responsive Iframes - W3Schools
Có thể bạn quan tâm
Learn how to create responsive iframes with CSS.
Responsive Iframes
Create an iframe that will keep the aspect ratio (4:3, 16:9, etc.) when resized:
What is aspect ratio? The aspect ratio of an element describes the proportional relationship between its width and its height. Two common video aspect ratios are 4:3 (the universal video format of the 20th century), and 16:9 (universal for HD television and European digital television, and for YouTube videos).
How To - Responsive Iframes
Step 1) Add HTML:
Use a container element, like <div>, and add the iframe inside of it:
Example
<div class="container"> <iframe class="responsive-iframe" src="https://www.youtube.com/embed/tgbNymZ7vqY"></iframe></div>Step 2) Add CSS:
Add a percentage value for padding-top to maintain the aspect ratio of the container DIV. The following example will create an aspect ratio of 16:9, which is the default aspect ratio of YouTube videos.
Example 16:9 Aspect Ratio
.container { position: relative; overflow: hidden; width: 100%; padding-top: 56.25%; /* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */}/* Then style the iframe to fit in the container div with full height and width */.responsive-iframe { position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height: 100%; } Try it Yourself »Other aspect ratios:
Example 4:3 Aspect Ratio
.container { padding-top: 75%; /* 4:3 Aspect Ratio */} Try it Yourself »Example 3:2 Aspect Ratio
.container { padding-top: 66.66%; /* 3:2 Aspect Ratio */} Try it Yourself »Example 8:5 Aspect Ratio
.container { padding-top: 62.5%; /* 8:5 Aspect Ratio */} Try it Yourself »Example 1:1 Aspect Ratio (Height and Width is Always Equal)
.container { padding-top: 100%; /* 1:1 Aspect Ratio */} Try it Yourself » ❮ Previous Next ❯ ★ +1 Sign in to track progressTừ khóa » Html Iframe Size Auto
-
Make Iframe Automatically Adjust Height According To The Contents ...
-
Automatically Adjust IFrame Height According To Its Contents Using ...
-
How To Adjust The Width And Height Of Iframe To Fit With Content In It
-
Html Iframe Width Auto Code Example
-
Auto-resize Iframe When Content Size Changes - WillMaster
-
How To Automatically Resize An Iframe | By Bret Cameron
-
Change Iframe Size Automatically To Fit Content & Prevent Scrollbars
-
HTML Iframe Height Attribute - W3Schools
-
3 Ways To Resize IFrames In HTML - WikiHow
-
Auto Resize IFrame (Same Origin) - Gists · GitHub
-
Auto Adjust HTML IFrame Height According To Page Contents JS
-
How To Resize Iframe Height Auto After Page Loaded Insideit - MSDN
-
How To Scale The Content Of
-
Iframe Height Auto Css