Example of CSS3 media query controlling the height of an iframe

Source: Internet
Author: User

In this scenario, you need to use CSS Media query to control the height of the IFRAME: for example, the height of an iframe video on a PC page is different from the height on the mobile Web page. The height of the IFRAME can only be set to a fixed height or a percentage of the div, we can control the height of this div through CSS query, to achieve the IFRAME on the PC and mobile phones at different heights.

First, we add in the style that doesn't define CSS Media query:

The code is as follows Copy Code

. iframe_height{
height:260px;
}

Then, when the width is greater than 1024px, set CSS Media Query:

The code is as follows Copy Code

@media screen and (min-width:1024px) {
. iframe_height{
height:460px;
}
}

When you refer to an IFRAME, you need to embed it in a Div, and the Div uses the. Iframe_height style and sets the iframe height to 100%, such as:

The code is as follows Copy Code

<div class= "Iframe_height" >
<iframe src= "/embed/xodi4otg5ntky" width= "100%" height= "100%" frameborder= "0" allowfullscreen= "allowfullscreen" ></iframe>
</div>

In this way, the high level of IFrame displayed on the PC Web page shows a slightly smaller iframe on the phone.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.