<?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: Naveen Kharwar</title>
    <description>The latest articles on DEV Community by Naveen Kharwar (@naveenkharwar).</description>
    <link>https://dev.to/naveenkharwar</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%2F259517%2F57879bc1-4595-42ce-bc45-58fbce0569b0.PNG</url>
      <title>DEV Community: Naveen Kharwar</title>
      <link>https://dev.to/naveenkharwar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/naveenkharwar"/>
    <language>en</language>
    <item>
      <title>How to center elements with CSS</title>
      <dc:creator>Naveen Kharwar</dc:creator>
      <pubDate>Sun, 26 Apr 2020 02:28:27 +0000</pubDate>
      <link>https://dev.to/naveenkharwar/how-to-center-elements-with-css-157c</link>
      <guid>https://dev.to/naveenkharwar/how-to-center-elements-with-css-157c</guid>
      <description>&lt;p&gt;If you just dived into web development I am sure that you are also suffering from this. &lt;/p&gt;

&lt;p&gt;There are tons of questions on the developer's forum like StackOverflow where people answered these questions nicely that how they center their elements but you will find that most of them don't explain why their method works and why some time that don't.&lt;/p&gt;

&lt;p&gt;I am here just summarize all possible ways to center an element and also let you know why and where to use them.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Center using margin
&lt;/h2&gt;

&lt;p&gt;The easiest way to center an element is &lt;code&gt;margin: 0 auto;&lt;/code&gt; what this means that we are setting top-bottom margin 0 and left-right to auto. &lt;br&gt;
Below snippet will clear the above statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* That means */&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best thing about this method is that we don't need any parent element to trigger this style. Good to use when you are creating a container or wrapper.&lt;br&gt;
so, here comes the restriction this method only works if we provide width to that element. &lt;br&gt;
Because we are providing left and right margin auto hence we need to give it a specific width so that browser can provide left-right margin to it.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Center using text-align
&lt;/h2&gt;

&lt;p&gt;If you have content inside a parent element and you just want to center that, then this method will be good. In sort &lt;code&gt;text-align: center;&lt;/code&gt; works as it is written means works only with text or image or anything inside that parent component. It won't center that element it center the content inside that element.&lt;/p&gt;

&lt;p&gt;You need to have a parent element to use this method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
&lt;span class="nc"&gt;.i-am-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Center using grid and flexbox
&lt;/h2&gt;

&lt;p&gt;This method requires you to have knowledge of the grid or flexbox, this is an advanced method. Flexbox and grid make centering elements easy and handier.&lt;/p&gt;

&lt;p&gt;with flexbox or grid, centering elements horizontal and vertical is also handy.&lt;/p&gt;

&lt;p&gt;Let me provide some examples.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/naveenkharwar/embed/zYvwqGp?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Center using position
&lt;/h2&gt;

&lt;p&gt;The CSS position property is amazing if you know how to use them. CSS Position absolute property is widely used when we want to animate an SVG on a webpage at any place or just want to place elements anywhere on the page.&lt;br&gt;
But with great powers comes great responsibility :p with position absolute the element will leave its flow from the page I mean it will be no more inside the container, The element is no more in the flow we can manage to put it anywhere, but also it will make problem in responsive you have to add media queries for appropriate screen sizes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.wrap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FF4136&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* magic begins more here */&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's start with the position I put the position absolute now we have full control over wrap element and put &lt;code&gt;left:50%&lt;/code&gt; left 50% will move the element exactly at the center of the main container where this element belongs! and &lt;code&gt;top:50%&lt;/code&gt; top:50%, the div will be pushed down 50% from the top and now we using &lt;code&gt;transform: translate(-50%, -50%);&lt;/code&gt; now this box is  absolutely centered vertically within its container using &lt;code&gt;translate(-50%,-50%)&lt;/code&gt; and we have a center div, center horizontal and vertical.&lt;/p&gt;

&lt;p&gt;feedbacks and suggestions are always welcome 🤗&lt;/p&gt;

&lt;h3&gt;
  
  
  Links you should check
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"&gt;margin - CSS: Cascading Style Sheets | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-align"&gt;text-align - CSS: Cascading Style Sheets | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Grid"&gt;grid - CSS: Cascading Style Sheets | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Flex"&gt;Flex - MDN Web Docs Glossary: Definitions of Web-related terms | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position"&gt;position - CSS: Cascading Style Sheets | MDN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  My other blogs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/naveenkharwar/scope-of-tailwindcss-e85"&gt;Scope of TailwindCSS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Scope of TailwindCSS</title>
      <dc:creator>Naveen Kharwar</dc:creator>
      <pubDate>Sat, 04 Apr 2020 11:13:59 +0000</pubDate>
      <link>https://dev.to/naveenkharwar/scope-of-tailwindcss-e85</link>
      <guid>https://dev.to/naveenkharwar/scope-of-tailwindcss-e85</guid>
      <description>&lt;p&gt;Hello everyone, I am Naveen Kharwar. I am a student as well as a programmer by passion. Being in quarantine I've got a lot of time so instead of wasting it in boredom, I decided to invest it in brushing up my blogging skills. Hence, I decided to write this blog.&lt;/p&gt;

&lt;p&gt;So, I am writing this blog about my experience with TailwindCSS.&lt;/p&gt;

&lt;p&gt;According to the offical website, TailwindCSS is a utility-first CSS framework for rapidly building custom designs. Some developers don't like it because it makes the HTML/JSX or any markup look busier. But I found it cool as I don't have to write any single CSS for a website it doesn't matter if it's a big as E-commerce or just a simple landing page.&lt;/p&gt;

&lt;p&gt;TailwindCSS is available as CDN as well as the NPM module. To take full advantage of Tailwind’s features I recommend you install it with NPM. Check more about the installation &lt;a href="https://tailwindcss.com/docs/installation/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With TailwindCSS you have full control over your component not like Bootstrap. You will not get ready-made styles classes you have to create your own.&lt;/p&gt;

&lt;p&gt;Let me show you an example of a button:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/naveenkharwar/embed/VwLONop?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wait a minute! WTH, I have to write that many classes for just a button but...but...but...let me explain why is this helpful.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1. Customization
&lt;/h3&gt;

&lt;p&gt;TailwindCSS comes with default design but with the use of its config file &lt;code&gt;tailwind.config.js&lt;/code&gt; you can customize everything from the size of the container to color, font, font size, etc. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Size
&lt;/h3&gt;

&lt;p&gt;We are in 2020 we are now more focused on performance rather than CSS Framework look at the size of the Bootstrap Gzip file is around 22.7kb 😲 just a CSS framework, and after that, you write your CSS o meet your website look same as design.&lt;br&gt;
and in TailwindCSS we use PurgeCSS, what PurgeCSS do is it scan your HTML and remove the CSS which are not being used after PurgeCss  the tailwind CSS file generated is around 10kb to 15kb except if you are adding your CSS&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Responsive
&lt;/h3&gt;

&lt;p&gt;No need to write media queries for responsive design, Yep Yep with TailWindCSS you don't need to write any media queries to meet responsiveness you can achieve this by prefix the utility with the break-point name, followed by a semicolon same goes with hover state.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/naveenkharwar/embed/dyoELrp?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  4. I hate naming things
&lt;/h3&gt;

&lt;p&gt;With TailwindCSS you don't need to worry about naming your CSS classes no naming. with the TailwindCSS Utility class mostly you don't need to write any name unless you are not writing your custom style.&lt;br&gt;
about 98% you don't need to write CSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Increase development
&lt;/h3&gt;

&lt;p&gt;When you are not writing CSS it directly increases your productivity you can have more focus on your development rather than writing a name like &lt;code&gt;.i-dont-like-naming-css&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's all I have experienced the TailwindCSS if these benefits seem interesting to you you should give TailwindCSS a try.&lt;br&gt;
I'll provide some link here that will help you with TailwindCSS :)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tailwindcss.com/docs/installation"&gt;Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tailwindcss.com/screencasts/"&gt;Screencasts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=nqNIy8HkEQ8"&gt;Tailwind CSS Tips, Tricks &amp;amp; Best Practices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me know what you feel about TailwindCSS in the comment. I like to know what others feel about Tailwind CSS&lt;br&gt;
Well, this is the first blog of mine I'll continue writing about my learning here 😃&lt;/p&gt;

&lt;p&gt;Thank You, Akshat Gupta, for the cover image.&lt;br&gt;
Check his designs &lt;a href="https://www.behance.net/helloakshat"&gt;Akshat Gupta on Behance&lt;/a&gt;&lt;br&gt;
Adding to this I like to thank my two friends who helped me in writing my first blog &lt;a href="https://www.blogsgeek.com/aditya-vikram-singh/"&gt;Aditya Vikram Singh&lt;/a&gt; and &lt;a href="https://sassyecoder.github.io/"&gt;Sneha Omer&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
