Skip to content

Instantly share code, notes, and snippets.

@acarabott
Created October 13, 2013 12:50
Show Gist options
  • Save acarabott/6961987 to your computer and use it in GitHub Desktop.
Save acarabott/6961987 to your computer and use it in GitHub Desktop.
Make embed codes responsive
.embed-wrap {
position: relative;
padding-top: 25px; /* IE6 workaround*/
height: 0;
object, embed, iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
function resize_embed($embed) {
$embed_width_matches = array();
$embed_height_matches = array();
preg_match('/width=\"([0-9]+)\"/', $embed, $embed_width_matches);
preg_match('/height=\"([0-9]+)\"/', $embed, $embed_height_matches);
$embed_width = intval($embed_width_matches[1]);
$embed_height = intval($embed_height_matches[1]);
$pad_bot = intval(($embed_height / $embed_width) * 100);
$embed = preg_replace(
array('/width=\"[0-9]+\"/', '/height=\"[0-9]+\"/' ),
array('', ''),
$embed
);
return '<div class="embed-wrap" style="padding-bottom: ' . $pad_bot . '%">' . $embed . '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment