Published on

Imagine You Create A Responsive Page Layout With Tailwind CSS Like An Expert. Follow These 6 Steps To Get There

responsive page layout

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 responsive page layout ui component

Layout with side/bottom bar and overflow content container

Why use Tailwind CSS to build a responsive page layout ui component?

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

The preview of responsive page layout ui component

Free download of the responsive page layout's source code

The source code of responsive page layout ui component

<script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script>


<section class="h-screen w-screen bg-gray-200 flex flex-col-reverse sm:flex-row min-h-0 min-w-0 overflow-hidden">
  <aside class="sm:h-full sm:w-16 w-full h-12 bg-gray-800 text-gray-200">
    <ul class="text-center flex flex-row sm:flex-col w-full">
      <li class="h-14 border-b border-gray-900 hidden sm:block">
        <a id="page-icon" href="/" class="h-full w-full hover:bg-gray-700 block p-3">
          <img class="object-contain h-full w-full" src="https://avatars1.githubusercontent.com/u/6157842?v=4"
            alt="open-source" />
        </a>
      </li>
      <li class="sm:border-b border-gray-900 flex-1 sm:w-full" title="Inbox">
        <a id="page-icon" href="/" class="h-full w-full hover:bg-gray-700 block p-3">
          <i class="fas fa-inbox fill-current"> </i>
        </a>
      </li>
      <li class="sm:border-b border-gray-900 flex-1 sm:w-full" title="Settings">
        <a id="page-icon" href="/" class="h-full w-full hover:bg-gray-700 block p-3">
          <i class="fas fa-cogs fill-current"> </i>
        </a>
      </li>
      <li class="sm:border-b border-gray-900 flex-1 sm:w-full" title="Users">
        <a id="page-icon" href="/" class="h-full  w-full hover:bg-gray-700 block p-3">
          <i class="fas fa-users fill-current"> </i>
        </a>
      </li>
    </ul>
  </aside>
  <main class="sm:h-full flex-1 flex flex-col min-h-0 min-w-0 overflow-auto">
    <nav class="border-b bg-white px-6 py-2 flex items-center min-w-0 h-14">
      <h1 class="font-semibold text-lg"></h1>
      <span class="flex-1"></span>
      <span class="mr-2">
        <input type="text" placeholder="Search"
          class="w-full border-2 px-2 py-1 border border-gray-300 rounded-sm focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent bg-gray-300 focus:bg-gray-100" />
      </span>
      <button
        class="ml-auto border rounded-full ml-2 w-10 h-10 text-center leading-none text-gray-200 bg-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent">
        <i class="fas fa-user fill-current"></i>
      </button>
    </nav>
    <section class="flex-1 pt-3 md:p-6 lg:mb-0 lg:min-h-0 lg:min-w-0">
      <div class="flex flex-col lg:flex-row h-full w-full">
        
        <div class="border pb-2 lg:pb-0 w-full lg:max-w-sm px-3 flex flex-row lg:flex-col flex-wrap lg:flex-nowrap">
        
          <!-- control content left -->
          <div class="bg-red-200 w-full h-24 min-h-0 min-w-0 mb-4"></div>
          <div class="bg-red-200 w-full h-24 min-h-0 min-w-0 mb-4"></div>

        </div>
        
        <div class="border h-full w-full lg:flex-1 px-3 min-h-0 min-w-0">

          <!-- overflow content right -->
          <div class="bg-green-200 w-full h-full min-h-0 min-w-0 overflow-auto">
            <div class="bg-pink-600 w-screen h-64"></div>
            <div class="bg-blue-600 w-full h-64"></div>
            <div class="bg-purple-600 w-screen h-64"></div>
            <div class="bg-red-600 w-full h-64"></div>
            <div class="bg-yellow-600 w-screen h-64"></div>
            <div class="bg-green-600 w-full h-64"></div>
          </div>

        </div>

      </div>
    </section>
    <footer class="px-6 py-3 border-t flex w-full items-end">
      <p class="text-gray-600">Made by @codingsafari</p>
      <div class="flex-1"></div>
      <button
        class="shadow-md ml-auto border rounded-full ml-2 w-14 h-14 text-center leading-none text-green-200 bg-green-600 hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent">
        <i class="fas fa-question fill-current"></i>
      </button>
    </footer>
  </main>
</section>

<style>
  @import url("https://fonts.googleapis.com/css2?family=Nunito&display=swap");

body {
  font-family: "Nunito", sans-serif;
}

main {
  font-size: clamp(0.9rem, 3vw, 1rem);
}

#page-icon img {
  -webkit-animation: cssfilter 3s infinite;
}


@-webkit-keyframes cssfilter {
  0%, 100%  {  
    filter: invert(75%) drop-shadow(0px 0px 2px blue) 
  }
  
  50% { 
    filter: invert(0%) drop-shadow(0px 0px 1px teal); 
  }
}
</style>

How to build a responsive page layout with Tailwind CSS?

Install tailwind css of verion 2.0.2

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

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

All the unility class needed to build a responsive page layout component

  • h-screen
  • w-screen
  • bg-gray-200
  • flex
  • flex-col-reverse
  • sm:flex-row
  • min-h-0
  • min-w-0
  • overflow-hidden
  • sm:h-full
  • sm:w-16
  • w-full
  • h-12
  • bg-gray-800
  • text-gray-200
  • text-center
  • flex-row
  • sm:flex-col
  • h-14
  • border-b
  • border-gray-900
  • hidden
  • sm:block
  • h-full
  • hover:bg-gray-700
  • block
  • p-3
  • sm:border-b
  • flex-1
  • sm:w-full
  • flex-col
  • overflow-auto
  • bg-white
  • px-6
  • py-2
  • text-lg
  • mr-2
  • border-2
  • px-2
  • py-1
  • border-gray-300
  • focus:border-transparent
  • bg-gray-300
  • focus:bg-gray-100
  • ml-auto
  • ml-2
  • w-10
  • h-10
  • bg-gray-400
  • pt-3
  • md:p-6
  • lg:mb-0
  • lg:min-h-0
  • lg:min-w-0
  • lg:flex-row
  • pb-2
  • lg:pb-0
  • lg:max-w-sm
  • px-3
  • lg:flex-col
  • flex-wrap
  • lg:flex-nowrap
  • bg-red-200
  • h-24
  • mb-4
  • lg:flex-1
  • bg-green-200
  • bg-pink-600
  • h-64
  • bg-blue-600
  • bg-purple-600
  • bg-red-600
  • bg-yellow-600
  • bg-green-600
  • py-3
  • border-t
  • text-gray-600
  • w-14
  • text-green-200
  • hover:bg-green-500

80 steps to build a responsive page layout component with Tailwind CSS

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

  2. Use w-screen to make an element span the entire width of the viewport.

  3. Control the background color of an element to gray-200 using the bg-gray-200 utilities.

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

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

  6. Use flex to create a block-level flex container at only small screen sizes.

  7. Set the minimum width/height of an element using the min-h-0 utilities.

  8. Set the minimum width/height of an element using the min-w-0 utilities.

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

  10. Use h-full to set an element’s height to 100% of its parent at only small screen sizes, as long as the parent has a defined height.

  11. Use sm:w-16 to set an element to a fixed width(4rem) at only small screen sizes.

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

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

  14. Control the background color of an element to gray-800 using the bg-gray-800 utilities.

  15. Control the text color of an element to gray-200 using the text-gray-200 utilities.

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

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

  18. Use flex to create a block-level flex container at only small screen sizes.

  19. Use h-14 to set an element to a fixed height(3.5rem).

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

  21. Control the border color of an element to gray-900 using the border-gray-900 utilities.

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

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

  24. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

  25. Control the background color of an element to gray-700 using the hover:bg-gray-700 utilities on hover.

  26. Use inline utilities to put the element on its own line and fill its parent.

  27. Control the padding on all sides of an element to 0.75rem using the p-3 utilities.

  28. Control the border color of an element to b using the sm:border-b utilities at only small screen sizes.

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

  30. Use w-full to set an element to a 100% based width at only small screen sizes.

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

  32. Use overflow-auto to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike .overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.

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

  34. Control the horizontal padding of an element to 1.5rem using the px-6 utilities.

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

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

  37. Control the margin on right side of an element to 0.5rem using the mr-2 utilities.

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

  39. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

  40. Control the vertical padding of an element to 0.25rem using the py-1 utilities.

  41. Control the border color of an element to gray-300 using the border-gray-300 utilities.

  42. Control the border color of an element to transparent using the focus:border-transparent utilities on focus.

  43. Control the background color of an element to gray-300 using the bg-gray-300 utilities.

  44. Control the background color of an element to gray-100 using the focus:bg-gray-100 utilities on focus.

  45. Control the margin on left side of an element to auto using the ml-auto utilities.

  46. Control the margin on left side of an element to 0.5rem using the ml-2 utilities.

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

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

  49. Control the background color of an element to gray-400 using the bg-gray-400 utilities.

  50. Control the padding on top side of an element to 0.75rem using the pt-3 utilities.

  51. Control the padding on all sides of an element to 1.5rem at only medium screen sizes using the md:p-6 utilities.

  52. Control the margin on bottom side of an element to 0rem at only large screen sizes using the lg:mb-0 utilities.

  53. Set the minimum width/height of an element using the lg:min-h-0 utilities at only large screen sizes.

  54. Set the minimum width/height of an element using the lg:min-w-0 utilities at only large screen sizes.

  55. Use flex to create a block-level flex container at only large screen sizes.

  56. Control the padding on bottom side of an element to 0.5rem using the pb-2 utilities.

  57. Control the padding on bottom side of an element to 0rem at only large screen sizes using the lg:pb-0 utilities.

  58. Set the maximum width/height of an element using the lg:max-w-sm utilities at only large screen sizes.

  59. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  60. Use flex to create a block-level flex container at only large screen sizes.

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

  62. Use flex to create a block-level flex container at only large screen sizes.

  63. Control the background color of an element to red-200 using the bg-red-200 utilities.

  64. Use h-24 to set an element to a fixed height(6rem).

  65. Control the margin on bottom side of an element to 1rem using the mb-4 utilities.

  66. Use flex to create a block-level flex container at only large screen sizes.

  67. Control the background color of an element to green-200 using the bg-green-200 utilities.

  68. Control the background color of an element to pink-600 using the bg-pink-600 utilities.

  69. Use h-64 to set an element to a fixed height(16rem).

  70. Control the background color of an element to blue-600 using the bg-blue-600 utilities.

  71. Control the background color of an element to purple-600 using the bg-purple-600 utilities.

  72. Control the background color of an element to red-600 using the bg-red-600 utilities.

  73. Control the background color of an element to yellow-600 using the bg-yellow-600 utilities.

  74. Control the background color of an element to green-600 using the bg-green-600 utilities.

  75. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

  76. Control the border color of an element to t using the border-t utilities.

  77. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  78. Use w-14 to set an element to a fixed width(3.5rem).

  79. Control the text color of an element to green-200 using the text-green-200 utilities.

  80. Control the background color of an element to green-500 using the hover:bg-green-500 utilities on hover.

Conclusion

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