Embed YouTube in IFrame
I have attached a YouTube video with the following link to the Magento site (Magento is not very important unless there is a plugin I don't know about)
<iframe width="640" height="360" src="http://www.youtube.com/embed/Zq-805aUM7M?feature=player_embedded" frameborder="0" allowfullscreen></iframe>
I don't think this piece of code is good because it is not responsive. How can I fix it?
source to share
To specifically target YouTube videos and not all frames or attachments, you can use an attribute selector based on the string present in src
.
iframe[src*=youtube]
{
max-width:100%;
height:100%;
}
This works for me, but anyway you can find more solutions here for additional (specific) cases
source to share
There are many tips on the Internet with suggestions to remove the "width" and "height" attributes, which in some cases is not possible. But user can override these attributes with CSS
.wrapper {
position: relative;
height: 0;
overflow: hidden;
padding-bottom: 56.25%; }
And iframe:
.wrapper iframe[width][height] {
position: absolute;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important; }
Note the [width] and [height] in the CSS selector and the "! Important" statements - they are required to override the iframe's width and height attributes.
source to share