<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vinay Kumar Dahiya</title>
    <description>The latest articles on DEV Community by Vinay Kumar Dahiya (@vinay__).</description>
    <link>https://dev.to/vinay__</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F755307%2F47dad83e-9952-4484-a2bc-104ff0ee7f6a.jpeg</url>
      <title>DEV Community: Vinay Kumar Dahiya</title>
      <link>https://dev.to/vinay__</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vinay__"/>
    <language>en</language>
    <item>
      <title>Overflows and React Slick</title>
      <dc:creator>Vinay Kumar Dahiya</dc:creator>
      <pubDate>Wed, 15 Dec 2021 17:04:30 +0000</pubDate>
      <link>https://dev.to/vinay__/overflows-and-react-slick-4do1</link>
      <guid>https://dev.to/vinay__/overflows-and-react-slick-4do1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Cross posted from &lt;a href="https://archimydes.dev/fourthact/blog/overflows-and-react-slick"&gt;Archimydes blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h3&gt;
  
  
  Why the post?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Here, I cover some of the problems I get stuck on, working as an Apprentice Software Engineer with &lt;a href="https://archimydes.dev/" rel="noreferrer"&gt;Archimydes - A Software Engineering Guild&lt;/a&gt;. The issues that I discuss here might not be as complicated per se, but they are something you could get stuck on for a while (like I did). I get stuck on web-related issues, solve them, and share the experiences here so that you don't repeat my mistakes! If that sounds good, read on.&lt;br&gt;
Happy reading! :-). &lt;/p&gt;
&lt;/blockquote&gt;



&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;I encountered this particular issue when I was using React Slick to make a carousel. We had specific images that were offset to the top, basically out of their original container elements, by design.&lt;/p&gt;


&lt;center&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HajSZx6e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tblh0tgb02p2v5hbwrcu.png" width="425" height="237"&gt;&lt;br&gt;
&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 1: Original Issue&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
So when you have a similar design, you may encounter this issue.&lt;br&gt;
&lt;br&gt;
&lt;h3&gt;
  
  
  The Diagnosis
&lt;/h3&gt;

&lt;p&gt;Observing the dev tools clearly shows how the image is being cut on top, probably due to some overflow CSS property. (Chrome dev tool is your best friend when it comes to debugging web-related issues, spending some time getting used to it will be an excellent investment).&lt;/p&gt;


&lt;center&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j-Io1_eK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3dqoic2efdnnstknhy9.png" width="880" height="529"&gt;&lt;br&gt;
&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 2: Highlighted image boundaries via dev tools&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;

&lt;p&gt;This happens because slick, by default, hides the overflow in all directions. The same is revealed via the chrome developer console:&lt;/p&gt;




&lt;center&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--igc90YzJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/glxql89hh6h1w58q5z0l.png" width="295" height="115"&gt;&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 3: Styles applied by react-slick&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;



&lt;h3&gt;
  
  
  Easy Fix, is it though?
&lt;/h3&gt;

&lt;p&gt;While exploring the HTML via the developer tools, I discovered that a class: &lt;em&gt;slick-list&lt;/em&gt; is being applied to the main items in the carousel. So, how about writing some custom CSS in your global styles file, targeting the &lt;em&gt;slick-list&lt;/em&gt; class ( discovered through chrome dev tools ) to make overflow visible.&lt;/p&gt;




&lt;center&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Nf9RMVg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hkd6x6nz11e3azkm203.png" width="315" height="126"&gt;&lt;br&gt;
&lt;/center&gt;



&lt;p&gt;This solved my problem, and the image was no longer cropped:&lt;/p&gt;


&lt;center&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YoPYxcJk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xfyuv2caluxq160x9w4.png" width="376" height="410"&gt;&lt;br&gt;
&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 4: The result of setting overflow to visible via custom CSS&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;

&lt;p&gt;But since I made overflow visible, as a &lt;strong&gt;side effect&lt;/strong&gt;, in another carousel, the content was creeping in from the previous and next slides.&lt;/p&gt;


&lt;center&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oPwuRBfy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hsfjlowlmgu8xas3mbq9.png" width="358" height="405"&gt;&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 5: Side effect of setting the overflow: visible&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;

&lt;p&gt;(And yes, I tried making just the overflow-y visible, it does not work for some reason).&lt;/p&gt;



&lt;h3&gt;
  
  
  The Actual Solution that worked
&lt;/h3&gt;

&lt;p&gt;Sometimes the simplest and safest solution is so straightforward that it almost seems like a hack, and as you can probably guess, so is the case here.&lt;/p&gt;



&lt;p&gt;The safest and most straightforward way to solve the problem, without impacting the rest of the application, is to just adjust the &lt;strong&gt;padding&lt;/strong&gt; and &lt;strong&gt;margin&lt;/strong&gt; on your original container and change the styles for content around it so that overall styling and placement don't get affected much.&lt;/p&gt;



&lt;p&gt;Something like :&lt;/p&gt;


&lt;center&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XYRfDrgt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t3yihqon61tk18ratgf2.png" width="462" height="241"&gt;&lt;br&gt;
&lt;/center&gt;



&lt;p&gt;This would essentially expand the slick slider container ( the one with hidden overflow ) upward, and the overflowing content would fit inside this extra space comfortably, thus eliminating the problem.&lt;/p&gt;



&lt;p&gt;The final result:&lt;/p&gt;




&lt;center&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g1W1m_rv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75jk45tomr7zyk2mp1bk.png" width="758" height="376"&gt;&lt;/center&gt;
&lt;br&gt;
&lt;center&gt;Figure 6: Solved problem (right) with highlighted margins (left)&lt;/center&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This post is a classic example of how ignoring the simple solution that is right in front of you while looking for something that seems more like "not-a-hack" can lead to so much more trouble down the road.&lt;/p&gt;



&lt;p&gt;Remember this, If it works and solves your problem, &lt;strong&gt;Simple is Good!&lt;/strong&gt;&lt;/p&gt;





&lt;p&gt;So that was it for this post. I hope you found this helpful and gained something from my short article. I would be glad if you could share your thoughts with me on Twitter &lt;a href="https://twitter.com/v_dahiya_" rel="noreferrer"&gt;v_dahiya_&lt;/a&gt; or LinkedIn &lt;a href="https://www.linkedin.com/in/vinay-kumar-dahiya/" rel="noreferrer"&gt;vinay-kumar-dahiya&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;I look forward to your comments and suggestions.&lt;/p&gt;



&lt;p&gt;Interested in joining the Guild?&lt;a href="https://archimydes.dev/devjoin/" rel="noreferrer"&gt;Join here&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>react</category>
    </item>
  </channel>
</rss>
