Skip to content

Instantly share code, notes, and snippets.

@DSchau
Created July 26, 2019 18:11
Show Gist options
  • Save DSchau/3fc23cdb4d86a822642781641d6cb63b to your computer and use it in GitHub Desktop.
Save DSchau/3fc23cdb4d86a822642781641d6cb63b to your computer and use it in GitHub Desktop.
A responsive iFrame for React
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>
)
@DSchau
Copy link
Author

DSchau commented Jul 26, 2019

^ note: this is using emotion, but you know, use whatever you like :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment