{"id":6580,"date":"2020-12-16T19:08:15","date_gmt":"2020-12-17T00:08:15","guid":{"rendered":"http:\/\/www.glajumedia.com\/en\/?p=6580"},"modified":"2022-03-22T21:49:21","modified_gmt":"2022-03-22T21:49:21","slug":"css-practices-create-responsive-image","status":"publish","type":"post","link":"https:\/\/www.gmedia.la\/en\/css-practices-create-responsive-image\/","title":{"rendered":"CSS Practices to Create Responsive Image"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Have any of you ever ask yourself about a mobile-friendly website? If you took the responsive design route, then you must establish a strategy to make a responsive image. The basic rules are simple after your master by starting scaling the images.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You might also face performance and art direction to solve some issues. There are many practices to create a responsive image and each of them with its weaknesses and strengths. This article will help you to fight two enormous enemies: responsive image and deadlines.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6582\" src=\"https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/ALA_407_responsive-images-in-practice-v1-300x125.png\" alt=\"responsive image issues\" width=\"605\" height=\"252\" \/><\/p>\n<h2><span style=\"font-weight: 400;\">PICTUREFILL<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The internet is worldwide, but we forget that not everyone has the same quality access to fiberoptic connections and 4G networks. Scott Jehl has realized this digital divide about the idea of mobile-first and responsive sites. Jehl has a <\/span><a href=\"https:\/\/github.com\/scottjehl\/picturefill\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">picturefill<\/span><\/a><span style=\"font-weight: 400;\"> script that proposed <code>&lt;picture&gt;<\/code> element. It is a JavaScript code that imitates the picture API.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Picturefill doesn&#8217;t need jQuery, but it requires the <code>picturefill.js<\/code> script. Another requirement for Picturefill is some special markup with divs to represent the image variation, differentiated by data-media attributes that act as media queries in CSS.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Since Picturefill requires a lot of custom markup, it isn&#8217;t the best choice if you cannot alter your website&#8217;s source code.\u00a0<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">NETFLIX WAY<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">It is a little trick that works everywhere, where you need to wrap your image with a relatively padded parent. Here, you will keep the responsive image ratio with a percentage on the padding property.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The code looks like this:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6588\" src=\"https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-16-at-7.00.11-PM-300x147.png\" alt=\"Netflix code\" width=\"522\" height=\"256\" srcset=\"https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-16-at-7.00.11-PM-300x147.png 522w, https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-16-at-7.00.11-PM-480x235.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 522px, 100vw\" \/><\/p>\n<h2><span style=\"font-weight: 400;\">ADAPTIVE IMAGE<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Adaptive images, created by Matt Wilcox, is a server-side solution that requires a little bit of JavaScript. However, the hard work is managed through the Apache 2 Web server, PHP 5.x, and the GD library.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To add it to your Web server, you should use the <code>.htaccess<\/code> file, next upload some PHP files to your website&#8217;s root directory. You have to add some JavaScript to your pages and modify some breakpoint variables in the PHP files. In this way, it will match your website&#8217;s media queries.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">An advantage of using <\/span><a href=\"http:\/\/adaptive-images.com\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Adaptive Image<\/span><\/a><span style=\"font-weight: 400;\"> is that it doesn&#8217;t require a custom markup on your images. When everything is completed, the PHP script will intercept any request for a picture and resize it as your specific breakpoint sizes and deliver it on your pages automatically.\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6586\" src=\"http:\/\/www.glajumedia.com\/en\/wp-content\/uploads\/2020\/12\/2802783-300x300.jpg\" alt=\"responsive image practices\" width=\"402\" height=\"402\" srcset=\"https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-300x300.jpg 300w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-1024x1024.jpg 1024w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-150x150.jpg 150w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-768x768.jpg 768w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-1536x1536.jpg 1536w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-1080x1080.jpg 1080w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-1280x1280.jpg 1280w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-980x980.jpg 980w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783-480x480.jpg 480w, https:\/\/www.gmedia.la\/en\/wp-content\/uploads\/2020\/12\/2802783.jpg 2000w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n<h2><span style=\"font-weight: 400;\">CAPTURING\/MOBIFY.JS 2.0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">It is a new feature from the in-development Mobify.js 2.0, which gives you access to the HTML. At this stage, you will be able to swap an image&#8217;s <code>src<\/code> attribute before the browser downloads it. Capturing is a technique that directly circumvents native browser preloading, which can cause a performance issue if it is misused.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The ways from above might not be the only ones, but not consider enough in your business site. Indeed, it can help you with <\/span><span style=\"font-weight: 400;\">CSS practices to create responsive images to <\/span><span style=\"font-weight: 400;\">improve your business site. Above all, developers at<\/span><a href=\"http:\/\/www.glajumedia.com\/en\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\"> Glajumedia<\/span><\/a><span style=\"font-weight: 400;\"> can give you that peace of mind by expanding your website.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6585\" src=\"https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/responsive-concept-illustration_114360-674-300x200.jpg\" alt=\"responsive image on different divices\" width=\"494\" height=\"329\" srcset=\"https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/responsive-concept-illustration_114360-674-300x200.jpg 494w, https:\/\/www.gmedia.la\/wp-content\/uploads\/2020\/12\/responsive-concept-illustration_114360-674-480x320.jpg 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 494px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have any of you ever ask yourself about a mobile-friendly website? If you took the responsive design route, then you must establish a strategy to make a responsive image.<\/p>\n","protected":false},"author":1,"featured_media":6583,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[38],"tags":[155,156,124,29],"class_list":["post-6580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-category-web-design","tag-css","tag-responsive-image","tag-web-development","tag-web-development-peru"],"_links":{"self":[{"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/posts\/6580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/comments?post=6580"}],"version-history":[{"count":0,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/posts\/6580\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/media\/6583"}],"wp:attachment":[{"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/media?parent=6580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/categories?post=6580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gmedia.la\/en\/wp-json\/wp\/v2\/tags?post=6580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}