{"id":1388,"date":"2016-07-01T04:05:58","date_gmt":"2016-06-30T22:05:58","guid":{"rendered":"http:\/\/promincproductions.com\/blog\/?p=1388"},"modified":"2024-03-08T20:45:13","modified_gmt":"2024-03-09T02:45:13","slug":"responsive-css-crop-youtube-thumbnail-black-bars","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/responsive-css-crop-youtube-thumbnail-black-bars\/","title":{"rendered":"Responsive CSS to Crop YouTube Thumbnail Black Bars"},"content":{"rendered":"<p>If you&#8217;ve ever use YouTube thumbnail images you&#8217;ve likely been as frustrated as me that they tend to come with black bars at the top and bottom of it. &nbsp;Given my video producer background and the history of YouTube I understand why they are there, but they are frustrating. &nbsp;You can learn more about the image sizes and formats in this post:&nbsp;<a href=\"https:\/\/promincproductions.com\/blog\/youtube-image-thumbnail-urls\/\" data-lasso-id=\"614\">YouTube Image Thumbnail URLs<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS.jpg\" rel=\"attachment wp-att-394\" data-lasso-id=\"615\" data-rel=\"lightbox-gallery-e6ngfBTg\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" width=\"500\" height=\"500\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS-500x500.jpg\" alt=\"HTML and CSS to create a responsive YouTube thumbnail image with playbutton and without black bars.\" class=\"wp-image-1394\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS-500x500.jpg 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS-150x150.jpg 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS-768x768.jpg 768w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS-600x600.jpg 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS.jpg 800w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption>HTML and CSS to create a responsive YouTube thumbnail image with playbutton and without black bars.<\/figcaption><\/figure><\/div>\n\n\n\n<p>So when you want to use these images in a webpage and crop off of the black bars at the top on bottom, and ensure that the image scales correctly in a responsive design website, it can be a bit tricky. &nbsp;There&#8217;s a lot to consider here. &nbsp;Not to mention that you&#8217;ll typically want to add a play button over the top of it as well and ensure that it&#8217;s always centered regardless of the window size.<\/p>\n\n\n\n<p>While it&#8217;s possible to write CSS that works in a responsive layout, it&#8217;s not widely accessible through a Google search. &nbsp;But I&#8217;ve come up with a solution, and thus wanted to share so it&#8217;s easy for me (or you) to find once again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Live Example<\/h2>\n\n\n\n<p>I&#8217;ve put a working example here on a JSFiddle:<\/p>\n\n\n\n<p><a href=\"https:\/\/jsfiddle.net\/PromInc\/y8xppfoj\/\" target=\"_blank\" rel=\"noopener\" data-lasso-id=\"616\">JSFiddle &#8211; Responsive YouTube Thumbnail Image 16:9<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTML<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;div class=\"ytImgContainer\"&gt;\n    &lt;a href=\"https:\/\/www.youtube.com\/watch?v=yZuWQTXZBHI&amp;width=640&amp;height=480\"&gt;\n        &lt;div class=\"ytImgWrapper\"&gt;\n            &lt;div class=\"ytImgThumbBox\"&gt;\n                &lt;img src=\"http:\/\/img.youtube.com\/vi\/yZuWQTXZBHI\/sddefault.jpg\" class=\"ytImgThumbImg\" alt=\"text\"&gt;\n                &lt;div class=\"ytImgThumbPlay\"&gt;\n                    &lt;img src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/video_play.png\" class=\"ytImgThumbPlayButton\"&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/a&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Responsive CSS<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">.ytImgContainer img {\n    max-width: 100%;\n    height: auto;\n}\n\n.ytImgContainer {\n    margin: 0 auto;\n    max-width: 604px;\n    width: 100%;\n}\n\n.ytImgContainer:after {\n    clear: both;\n}\n\n.ytImgContainer:before,\n.ytImgContainer:after {\n    content: \"\";\n    display: table;\n}\n\ndiv.ytImgThumbBox{\n    position: relative !important;\n    width: 100% !important;\n    height: 100% !important;\n    overflow: hidden;\n}\n\ndiv.ytImgThumbPlay{\n    position: absolute !important;\n    top: 50% !important;\n    left: 50% !important;\n    width:48px !important;\n    height:48px !important;\n    margin: -24px 0 0 -24px !important;\n}\n\nimg.ytImgThumbImg{\n    width: 100% !important;\n    height: 100% !important;\n    margin: -9.5% 0px -12%;\n}<\/pre>\n\n\n\n<p>I hope this helps!<\/p>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever use YouTube thumbnail images you&#8217;ve likely been as frustrated as me that they tend to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1394,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[48,25,5],"tags":[524],"class_list":["post-1388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-responsive-website","category-website-development","tag-youtube"],"jetpack_featured_media_url":"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2016\/07\/YouTube-Responsive-Thumbnail-CSS.jpg","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-mo","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=1388"}],"version-history":[{"count":6,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions"}],"predecessor-version":[{"id":3583,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions\/3583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media\/1394"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=1388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=1388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=1388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}