Published on

Most Effective Ways To Build A Footer With Collapsing Sections With Tailwind CSS

Tags
Footer with collapsing sections

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.

Inspired by fashion sites like lululemon, best for sites that need a lot of info in the footer. at mobile widths the sections will collapse (requires javascript to toggle visibility).

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

Free download of the Footer with collapsing sections's source code

<footer class="mt-16">
      <div class="border-t md:px-4 md:pt-10 md:pb-5">
        <div class="flex flex-wrap md:max-w-screen-lg mx-auto">
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Lorem ipsum dolor sit amet consectetur adipiscing elit maecenas
                mattis
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Lorem ipsum dolor sit amet consectetur adipiscing elit maecenas
              mattis
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Fusce vel sem</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Ut venenatis tellus</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Vestibulum</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Nunc at ipsum</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Ut porta
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Ut porta
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Pellentesque rhoncus</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Aenean</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Curabitur bibendum</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Phasellus non mi</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Duis accumsa</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Curabitur nec enim</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Fusce ut augue</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Praesent elementum
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Praesent elementum
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Mauris mattis nunc</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Nunc viverra risus</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Etiam a libero</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Aenean gravida orci in sem varius
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Aenean gravida orci in sem varius
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Cras id ipsum</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Donec a lorem
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Donec a lorem
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Sed a diam</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Nullam luctus felis</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Sed euismod</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Integer interdum
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Integer interdum
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Dignissim gravida</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Eu mollis elit</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Hendrerit purus id</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Ut luctus dui tincidunt</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Pellentesque at ligula</a>
                </li>
              </ul>
            </article>
          </section>
          <section
            class="relative text-gray-700 font-light font-light border-b px-4 pb-4 md:py-3 w-full md:border-none md:w-1/4"
          >
            <div class="md:hidden">
              <button
                onclick="toggleFooterSection(event)"
                class="uppercase text-xs font-bold tracking-wider text-pink-700 focus:outline-none border-t border-white py-4 w-full text-left"
                type="button"
              >
                Quisque
              </button>
            </div>
            <a
              class="uppercase text-xs font-bold tracking-wider text-pink-700 hidden md:block"
              href="#"
            >
              Quisque
            </a>
            <article class="h-0 md:h-auto -mt-4 md:mt-0 overflow-hidden">
              <ul class="my-5 text-sm tracking-wide">
                <li class="my-3 tracking-wide">
                  <a href="#">Finibus nulla eget</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Pellentesque</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Duis efficitur</a>
                </li>
                <li class="my-3 tracking-wide">
                  <a href="#">Cras at lacus</a>
                </li>
              </ul>
            </article>
          </section>
        </div>
      </div>
      <div class="max-w-screen-lg mx-auto border-none px-4">
        <section
          class="flex flex-col md:flex-row md:justify-between md:border-solid md:border-t text-gray-700 font-light text-sm pt-4 pb-6 md:pt-5 md:pb-6 w-full"
        >
          <div>
            <p class="leading-8 tracking-wide">
              &copy; Lorem Ipsum Co., 123 Lorem Street, New York, NY
            </p>
          </div>
          <div>
            <p class="leading-8 tracking-wide">Privacy Policy</p>
          </div>
        </section>
      </div>
    </footer>
    <script>
      function toggleFooterSection(e) {
        const list = e.target.parentElement.parentElement.querySelector(
          "article"
        );
        if (list.classList.contains("h-0")) {
          list.classList.remove("h-0");
        } else {
          list.classList.add("h-0");
        }
      }
    </script>

Install tailwind css of verion 1.4.6

Use the link html tag to import the stylesheet of Tailwind CSS of the version 1.4.6

<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
  • mt-16
  • border-t
  • md:px-4
  • md:pt-10
  • md:pb-5
  • flex
  • flex-wrap
  • md:max-w-screen-lg
  • mx-auto
  • relative
  • text-gray-700
  • border-b
  • px-4
  • pb-4
  • md:py-3
  • w-full
  • md:border-none
  • md:w-1/4
  • md:hidden
  • text-xs
  • text-pink-700
  • border-white
  • py-4
  • text-left
  • hidden
  • md:block
  • h-0
  • md:h-auto
  • -mt-4
  • md:mt-0
  • overflow-hidden
  • my-5
  • text-sm
  • my-3
  • max-w-screen-lg
  • border-none
  • flex-col
  • md:flex-row
  • md:border-solid
  • md:border-t
  • pt-4
  • pb-6
  • md:pt-5
  • md:pb-6
  1. Control the margin on top side of an element to 4rem using the mt-16 utilities.

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

  3. Control the horizontal padding of an element to 1rem at only medium screen sizes using the md:px-4 utilities.

  4. Control the padding on top side of an element to 2.5rem at only medium screen sizes using the md:pt-10 utilities.

  5. Control the padding on bottom side of an element to 1.25rem at only medium screen sizes using the md:pb-5 utilities.

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

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

  8. Set the maximum width/height of an element using the md:max-w-screen-lg utilities at only medium screen sizes.

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

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

  11. Control the text color of an element to gray-700 using the text-gray-700 utilities.

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

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

  14. Control the padding on bottom side of an element to 1rem using the pb-4 utilities.

  15. Control the vertical padding of an element to 0.75rem at only medium screen sizes using the md:py-3 utilities.

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

  17. Control the border color of an element to none using the md:border-none utilities at only medium screen sizes.

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

  19. Use hidden to set an element to display: none and remove it from the page layout at only medium screen sizes.

  20. Control the text color of an element to xs using the text-xs utilities.

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

  22. Control the border color of an element to white using the border-white utilities.

  23. Control the vertical padding of an element to 1rem using the py-4 utilities.

  24. Control the text color of an element to left using the text-left utilities.

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

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

  27. Use h-0 to set an element to a fixed height(0rem).

  28. Use md:h-auto to set an element to a fixed height(auto) at only medium screen sizes.

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

  30. Control the margin on top side of an element to 0rem at only medium screen sizes using the md:mt-0 utilities.

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

  32. Control the vertical margin of an element to 1.25rem using the my-5 utilities.

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

  34. Control the vertical margin of an element to 0.75rem using the my-3 utilities.

  35. Set the maximum width/height of an element using the max-w-screen-lg utilities.

  36. Control the border color of an element to none using the border-none utilities.

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

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

  39. Control the border color of an element to solid using the md:border-solid utilities at only medium screen sizes.

  40. Control the border color of an element to t using the md:border-t utilities at only medium screen sizes.

  41. Control the padding on top side of an element to 1rem using the pt-4 utilities.

  42. Control the padding on bottom side of an element to 1.5rem using the pb-6 utilities.

  43. Control the padding on top side of an element to 1.25rem at only medium screen sizes using the md:pt-5 utilities.

  44. Control the padding on bottom side of an element to 1.5rem at only medium screen sizes using the md:pb-6 utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to make a Footer with collapsing sections components, learn and follow along to implement your own components.