

( Larger view)Īnd here’s how it will look on a screen that is 320 pixels wide: Here’s how it will look on a desktop:ĭesktop screenshot of the video resizing the screen’s width. Having done this, the video will now resize with the screen’s width. The width and height properties ensure that the video takes up 100% of the space used by the containing element (which is actually set with padding).The top and left properties position the iframe correctly in the containing element.If the iframe were positioned normally, we would have given it a height of 0 as well. Absolute positioning is used because the containing element has a height of 0.This targets iframes inside containers with the. Setting overflow to hidden ensures that any content protruding outside of this element will be hidden from view.We do not set the width because it will automatically resize with the responsive element that contains this div. The height is set to 0 because padding-bottom gives the element the height it needs.The padding-top value is set to 30 pixels to allow space for the chrome - this is specific to YouTube videos.For a video with a 4:3 aspect ratio, we set padding-bottom to 75%. In this case, the aspect ratio is 16:9, which means that the height will be 56.25% of the width. The padding-bottom value is calculated out of the aspect ratio of the video.Setting the position to relative lets us use absolute positioning for the iframe itself, which we’ll get to shortly.As proposed by Thierry Koblentz in his ALA article “Creating Intrinsic Ratios For Video”, we can use the following snippet in our style sheet: The CSSįirst, we style the containing wrapper with the. The next step is to add styling to this new wrapper and the iframe within it. To make embedded content responsive, you need to add a containing wrapper around the iframe.
Iframe no border how to#
First, I’ll show you how to do this with embedded video, and then with calendars. ( Larger view)įortunately, there is a way around this using CSS. Screenshot taken from an iPhone in portrait mode (320px wide). The screenshot is taken from an iPhone in portrait mode (320 pixels wide), and the rest of the page has been shrunk so that the embedded content fits the screen.
Iframe no border code#
In the example below, I’ve added the code above to a page of my blog. The width attribute means that, on a screen narrower than 560 pixels, the embedded content will protrude outside of its containing element, breaking the layout. And you can’t fix this in your style sheet, unfortunately. Remove these and the iframe will disappear because it would have no dimensions. However, you’ll notice that our iframe includes width and height attributes. This iframe enables external content to be displayed on your website, because it includes a URL that points to the source of the streamed content. When you embed content from an external source, the code will include an iframe: The two main ways to embed video on a website are the HTML5 video element, which doesn’t work in legacy versions of Internet Explorer, and Flash, which doesn’t work on iOS devices and isn’t standards-compliant. I tend to recommend to my clients that they host video with YouTube because it will save them server space and, regardless of the user’s browser or device, YouTube will display the video correctly. Services such as YouTube provide code that you can copy and paste into your own website to embed content. I’ve used techniques I learned from his tutorial and expanded on them here for additional content types such as calendars. Note: This technique was originally detailed in Thierry Koblenz’s excellent tutorial ‘ Creating Intrinsic Ratios for Video’.
