Published on

The Ninja Guide To How To Make A Sidebar With Tailwind CSS Better

Sidebar

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

The description of Sidebar ui component

Sidebar

Why use Tailwind CSS to build a Sidebar ui component?

  • It can make the building process of Sidebar ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Sidebar component file.

The preview of Sidebar ui component

Free download of the Sidebar's source code

The source code of Sidebar ui component

<div class="flex">
	<div class="md:flex w-2/5 md:w-1/4 h-screen bg-white border-r hidden">
		<div class="mx-auto py-10">
			<h1 class="text-2xl font-bold mb-10 cursor-pointer text-[#EC5252] duration-150">Asason</h1>
			<ul>
				<li class="flex space-x-2 mt-10 cursor-pointer hover:text-[#EC5252] duration-150">
					<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
						stroke="currentColor">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
							d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
					</svg>
					<span class="font-semibold">Home</span>
				</li>
				<li class="flex space-x-2 mt-10 cursor-pointer hover:text-[#EC5252] duration-150">
					<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
						stroke="currentColor">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
							d="M16 4v12l-4-2-4 2V4M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
					</svg>
					<span class="font-semibold">All Courses</span>
				</li>
				<li class="flex space-x-2 mt-10 cursor-pointer hover:text-[#EC5252] duration-150">
					<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
						stroke="currentColor">
						<path d="M12 14l9-5-9-5-9 5 9 5z" />
						<path
							d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z" />
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
							d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222" />
					</svg>
					<span class="font-semibold">My Course</span>
				</li>
				<li class="flex space-x-2 mt-10 cursor-pointer hover:text-[#EC5252] duration-150">
					<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
						stroke="currentColor">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
							d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
					</svg>
					<span class="font-semibold">Profile</span>
				</li>
				<li class="flex space-x-2 mt-10 cursor-pointer hover:text-[#EC5252] duration-150">
					<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
						stroke="currentColor">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
							d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4" />
					</svg>
					<span class="font-semibold">Setthing</span>
				</li>
				<button class="w-full mt-10 bg-[#EC5252] rounded-full py-1.5 text-white">Learn</button>
			</ul>
		</div>
	</div>
	<main class="min-h-screen w-full bg-white">
		<nav class="flex items-center justify-between px-10 bg-white py-6 border-b">
			<div class="flex items-center bg-gray-100 px-4 py-2 rounded-md space-x-3 w-96">
				<input type="text" placeholder="search" class="bg-gray-100 outline-none w-full" />
				<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 cursor-pointer text-gray-500" fill="none"
					viewBox="0 0 24 24" stroke="currentColor">
					<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
						d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
				</svg>
			</div>
			<div class="flex items-center space-x-4">
				<img class="w-8 rounded-full" src="https://imagez.tmz.com/image/f7/1by1/2021/12/14/f7703994b69d48ca802df55729a2325c_xl.jpg" alt="Elon Musk" />
				<p class="hidden md:block">Elon Musk</p>
			</div>
		</nav>
		<div class="mx-6">
			<h1 class="my-6 text-3xl">All Courses</h1>
			<div class="md:flex  space-y-3 md:space-y-0 md:space-x-4 mt-6">
				<div class="h-90 bg-gradient-to-r rounded-md from-indigo-600 to-purple-600 p-10">
					<p class="text-3xl font-thin text-indigo-50 cursor-pointer">How to do Basic Jumping and how to
						landing safely</p>
					<div class="flex items-center mt-4 space-x-4">
						<img class="w-10 h-10 rounded-full cursor-pointer" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
						<div>
							<h3 class="text-indigo-50 font-semibold cursor-pointer">Thomas Hope</h3>
							<p class="text-indigo-50 text-sm font-thin">53K views • 2 weeks ago</p>
						</div>
					</div>
				</div>
				<div class="h-90 bg-gradient-to-r rounded-md from-indigo-600 to-purple-600 p-10">
					<p class="text-3xl font-thin text-indigo-50 cursor-pointer">How to do Basic Jumping and how to
						landing safely</p>
					<div class="flex items-center mt-4 space-x-4">
						<img class="w-10 h-10 rounded-full cursor-pointer" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
						<div>
							<h3 class="text-indigo-50 font-semibold cursor-pointer">Thomas Hope</h3>
							<p class="text-indigo-50 text-sm font-thin">53K views • 2 weeks ago</p>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="mx-6 grid grid-cols-2 gap-6 md:grid-cols-3 lg:grid-cols-4 mt-10">
			<div class="shadow-lg rounded-t-md overflow-hidden ">
				<div class="">
					<img class="w-sm" src="https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=600&q=60" alt="" />
					<div class="p-2 relative">
						<p class="text-lg mt-6 font-semibold">Basic how to ride your skateboard comfortly</p>
						<p>53K views • 2 weeks ago</p>
						<img class="h-12 w-12 rounded-full absolute -top-6 p-0.5 border-2 right-6" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
      </div>
					</div>
				</div>
				<div class="shadow-lg rounded-t-md overflow-hidden">
					<div class="">
						<img class="w-sm" src="https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=600&q=60" alt="" />
						<div class="p-2 relative">
							<p class="text-lg mt-6 font-semibold">Basic how to ride your skateboard comfortly</p>
							<p>53K views • 2 weeks ago</p>
							<img class="h-12 w-12 rounded-full absolute -top-6 p-0.5 border-2 right-6" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
      </div>
						</div>
					</div>
					<div class="shadow-lg rounded-t-md overflow-hidden ">
						<div class="">
							<img class="w-sm" src="https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=600&q=60" alt="" />
							<div class="p-2 relative">
								<p class="text-lg mt-6 font-semibold">Basic how to ride your skateboard comfortly</p>
								<p>53K views • 2 weeks ago</p>
								<img class="h-12 w-12 rounded-full absolute -top-6 p-0.5 border-2 right-6" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
      </div>
							</div>
						</div>
						<div class="shadow-lg rounded-t-md overflow-hidden ">
							<div class="">
								<img class="w-sm" src="https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=600&q=60" alt="" />
								<div class="p-2 relative">
									<p class="text-lg mt-6 font-semibold">Basic how to ride your skateboard comfortly
									</p>
									<p>53K views • 2 weeks ago</p>
									<img class="h-12 w-12 rounded-full absolute -top-6 p-0.5 border-2 right-6" src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" alt="" />
                  </div>
								</div>
							</div>
						</div>
					</div>
					<footer class="text-center py-6 bg-gray-100">
						Copyright &copy; 2022 dej45.com Template by Namina
					</footer>
          </main>
</div>

How to build a Sidebar with Tailwind CSS?

Install tailwind css of verion 2.2.19

Use the script html tag to import the script of Tailwind CSS of the version 2.2.19

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to build a Sidebar component

  • flex
  • md:flex
  • w-2/5
  • md:w-1/4
  • h-screen
  • bg-white
  • border-r
  • hidden
  • mx-auto
  • py-10
  • text-2xl
  • mb-10
  • text-[#EC5252]
  • mt-10
  • hover:text-[#EC5252]
  • h-6
  • w-6
  • w-full
  • bg-[#EC5252]
  • py-1.5
  • text-white
  • min-h-screen
  • px-10
  • py-6
  • border-b
  • bg-gray-100
  • px-4
  • py-2
  • w-96
  • h-5
  • w-5
  • text-gray-500
  • w-8
  • md:block
  • mx-6
  • my-6
  • text-3xl
  • mt-6
  • h-90
  • bg-gradient-to-r
  • p-10
  • text-indigo-50
  • mt-4
  • w-10
  • h-10
  • text-sm
  • grid
  • grid-cols-2
  • gap-6
  • md:grid-cols-3
  • lg:grid-cols-4
  • overflow-hidden
  • w-sm
  • p-2
  • relative
  • text-lg
  • h-12
  • w-12
  • absolute
  • -top-6
  • p-0.5
  • border-2
  • right-6
  • text-center

64 steps to build a Sidebar component with Tailwind CSS

  1. Use flex to create a block-level flex container.

  2. Use flex to create a block-level flex container at only medium screen sizes.

  3. Use w-2/5 to set an element to a fixed width(2/5).

  4. Use md:w-1/4 to set an element to a fixed width(1/4) at only medium screen sizes.

  5. Use h-screen to make an element span the entire height of the viewport.

  6. Control the background color of an element to white using the bg-white utilities.

  7. Control the border color of an element to r using the border-r utilities.

  8. Use hidden to set an element to display: none and remove it from the page layout.

  9. Control the horizontal margin of an element to auto using the mx-auto utilities.

  10. Control the vertical padding of an element to 2.5rem using the py-10 utilities.

  11. Control the text color of an element to 2xl using the text-2xl utilities.

  12. Control the margin on bottom side of an element to 2.5rem using the mb-10 utilities.

  13. Control the text color of an element to [#EC5252] using the text-[#EC5252] utilities.

  14. Control the margin on top side of an element to 2.5rem using the mt-10 utilities.

  15. Control the text color of an element to [#EC5252] on hover using the hover:text-[#EC5252] utilities.

  16. Use h-6 to set an element to a fixed height(1.5rem).

  17. Use w-6 to set an element to a fixed width(1.5rem).

  18. Use w-full to set an element to a 100% based width.

  19. Control the background color of an element to [#EC5252] using the bg-[#EC5252] utilities.

  20. Control the vertical padding of an element to 1.5 using the py-1.5 utilities.

  21. Control the text color of an element to white using the text-white utilities.

  22. Set the minimum width/height of an element using the min-h-screen utilities.

  23. Control the horizontal padding of an element to 2.5rem using the px-10 utilities.

  24. Control the vertical padding of an element to 1.5rem using the py-6 utilities.

  25. Control the border color of an element to b using the border-b utilities.

  26. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  27. Control the horizontal padding of an element to 1rem using the px-4 utilities.

  28. Control the vertical padding of an element to 0.5rem using the py-2 utilities.

  29. Use w-96 to set an element to a fixed width(24rem).

  30. Use h-5 to set an element to a fixed height(1.25rem).

  31. Use w-5 to set an element to a fixed width(1.25rem).

  32. Control the text color of an element to gray-500 using the text-gray-500 utilities.

  33. Use w-8 to set an element to a fixed width(2rem).

  34. Use inline utilities to put the element on its own line and fill its parent at only medium screen sizes.

  35. Control the horizontal margin of an element to 1.5rem using the mx-6 utilities.

  36. Control the vertical margin of an element to 1.5rem using the my-6 utilities.

  37. Control the text color of an element to 3xl using the text-3xl utilities.

  38. Control the margin on top side of an element to 1.5rem using the mt-6 utilities.

  39. Use h-90 to set an element to a fixed height(22.5rem).

  40. Control the background color of an element to gradient-to-r using the bg-gradient-to-r utilities.

  41. Control the padding on all sides of an element to 2.5rem using the p-10 utilities.

  42. Control the text color of an element to indigo-50 using the text-indigo-50 utilities.

  43. Control the margin on top side of an element to 1rem using the mt-4 utilities.

  44. Use w-10 to set an element to a fixed width(2.5rem).

  45. Use h-10 to set an element to a fixed height(2.5rem).

  46. Control the text color of an element to sm using the text-sm utilities.

  47. Use grid to create a grid container.

  48. Use grid to create a grid container.

  49. To specify the width between columns, you can use the gap-6 utilities.

  50. Use grid to create a grid container at only medium screen sizes.

  51. Use grid to create a grid container at only large screen sizes.

  52. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  53. Use w-sm to set an element to a fixed width(sm).

  54. Control the padding on all sides of an element to 0.5rem using the p-2 utilities.

  55. Use relative to position an element according to the normal flow of the document.

  56. Control the text color of an element to lg using the text-lg utilities.

  57. Use h-12 to set an element to a fixed height(3rem).

  58. Use w-12 to set an element to a fixed width(3rem).

  59. Use absolute to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.

  60. Use the -top-6 utilities to set the top position of a positioned element to -1.5rem.

  61. Control the padding on all sides of an element to 0.5 using the p-0.5 utilities.

  62. Control the border color of an element to 0.5rem using the border-2 utilities.

  63. Use the right-6 utilities to set the right position of a positioned element to 1.5rem.

  64. Control the text color of an element to center using the text-center utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to build a Sidebar components, learn and follow along to implement your own components.