Skip to content

Commit 1a10ed6

Browse files
committed
fix: make YouTube/SlideShare embeds responsive on mobile
1 parent 57fc2c4 commit 1a10ed6

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
<iframe width="800" height="450" src="https://www.youtube.com/embed/vcCgLqE4J3Q" frameborder="0" allowfullscreen></iframe>
1+
<div class="responsive-embed youtube">
2+
<iframe src="https://www.youtube.com/embed/vcCgLqE4J3Q" frameborder="0" allowfullscreen></iframe>
3+
</div>
4+
25
<br />
3-
<iframe src="https://www.slideshare.net/slideshow/embed_code/key/94wzhRi8Sxavr" width="800" height="500" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:0px solid #CCC; border-width:0px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe>
6+
7+
<div class="responsive-embed slideshare">
8+
<iframe src="https://www.slideshare.net/slideshow/embed_code/key/94wzhRi8Sxavr" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen></iframe>
9+
</div>

assets/main.scss

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,33 @@ footer span {
309309
}
310310
}
311311

312-
// Embedded content (YouTube, SlideShare, etc.) — subtle grey background so they're not blank white rectangles
313-
.post iframe {
314-
background: #f4f4f4;
315-
border-radius: 4px;
312+
// Responsive embeds (YouTube, SlideShare, etc.)
313+
// Uses the classic padding-bottom aspect-ratio hack — works everywhere.
314+
// Prevents horizontal overflow from hardcoded iframe widths on mobile.
315+
.post .responsive-embed {
316+
position: relative;
317+
width: 100%;
318+
margin: 1.5rem 0;
319+
overflow: hidden;
320+
321+
iframe {
322+
position: absolute;
323+
top: 0;
324+
left: 0;
325+
width: 100%;
326+
height: 100%;
327+
border: 0;
328+
background: #f4f4f4;
329+
border-radius: 4px;
330+
}
331+
}
332+
333+
// 16:9 for YouTube / Vimeo
334+
.post .responsive-embed.youtube {
335+
padding-bottom: 56.25%;
336+
}
337+
338+
// SlideShare embeds are slightly taller than 16:9
339+
.post .responsive-embed.slideshare {
340+
padding-bottom: 62.5%;
316341
}

0 commit comments

Comments
 (0)