Created
July 26, 2019 18:11
-
-
Save DSchau/3fc23cdb4d86a822642781641d6cb63b to your computer and use it in GitHub Desktop.
A responsive iFrame for React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
export default function IFrame({ src, height, title, width, ...rest }) { | |
return ( | |
<div | |
className={`gatsby-resp-iframe-wrapper`} | |
css={{ | |
paddingBottom: `${(height / width) * 100}%`, | |
position: `relative`, | |
height: 0, | |
overflow: `hidden`, | |
"iframe, object": { | |
position: `absolute`, | |
top: 0, | |
left: 0, | |
width: `100%`, | |
height: `100%`, | |
}, | |
}} | |
> | |
<iframe src={src} title={title} {...rest} /> | |
</div> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
^ note: this is using emotion, but you know, use whatever you like :)