Published on

Surprisingly Effective Ways To Build A Hero-component With Tailwind CSS

Tags
hero-component

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 hero-component ui component

Got from dribble.com

Why use Tailwind CSS to make a hero-component ui component?

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

The preview of hero-component ui component

Free download of the hero-component's source code

The source code of hero-component ui component

<div class="flex flex-wrap md items-center h-screen">
      <div class="bg-white w-full md:w-1/2 h-screen">
        <div class="mx-32">
          <h1 class="text-6xl font-bold mt-16">Tokyo</h1>

          <!-- country region island -->
          <div class="flex mt-16 font-light text-gray-500">
            <div class="pr-4">
              <span class="uppercase">Country</span>
              <p class="text-2xl text-gray-900 font-semibold pt-2">Japan</p>
            </div>
            <div class="pr-4">
              <span class="uppercase">Region</span>
              <p class="text-2xl text-gray-900 font-semibold pt-2">Kanto</p>
            </div>
            <div class="pr-4">
              <span class="uppercase">island</span>
              <p class="text-2xl text-gray-900 font-semibold pt-2">Honshu</p>
            </div>
          </div>

          <!-- description -->
          <div
            class="description w-full sm: md:w-2/3 mt-16 text-gray-500 text-sm"
          >
            Tokyo, Japan’s busy capital, mixes the ultramodern and the
            traditional, from neon-lit skyscrapers to historic temples. The
            opulent Meiji Shinto Shrine is known for its towering gate and
            surrounding woods. The Imperial Palace sits amid large public
            gardens
          </div>

          <button class="uppercase mt-5 text-sm font-semibold hover:underline">
            read more
          </button>
        </div>
      </div>
      <div class="bg-red-600 w-full md:w-1/2 h-screen">
        <img
          src="https://source.unsplash.com/7H77FWkK_x4/1600x900"
          class="h-screen w-full"
          alt=""
        />
      </div>
    </div>

How to make a hero-component with Tailwind CSS?

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">

All the unility class needed to make a hero-component component

  • flex
  • flex-wrap
  • h-screen
  • bg-white
  • w-full
  • md:w-1/2
  • mx-32
  • text-6xl
  • mt-16
  • text-gray-500
  • pr-4
  • text-2xl
  • text-gray-900
  • pt-2
  • md:w-2/3
  • text-sm
  • mt-5
  • bg-red-600

18 steps to make a hero-component component with Tailwind CSS

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

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

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

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

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

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

  7. Control the horizontal margin of an element to 8rem using the mx-32 utilities.

  8. Control the text color of an element to 6xl using the text-6xl utilities.

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

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

  11. Control the padding on right side of an element to 1rem using the pr-4 utilities.

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

  13. Control the text color of an element to gray-900 using the text-gray-900 utilities.

  14. Control the padding on top side of an element to 0.5rem using the pt-2 utilities.

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

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

  17. Control the margin on top side of an element to 1.25rem using the mt-5 utilities.

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

Conclusion

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