Published on

Beginners Guide: Make A Flight Card With Tailwind CSS

Flight Card

As a beginner in FrontEnd development, creating a UI component can be challenging. However, with the right tools and guidance, it can be a fun and rewarding experience. In this article, we will explore how to create a Flight Card UI component using Tailwind CSS.

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that enables developers to create custom designs without writing CSS from scratch. It provides a set of pre-defined CSS classes that can be used to style HTML elements. With Tailwind CSS, developers can easily create responsive and scalable designs.

The description of Flight Card UI component

A Flight Card is a UI component that displays information about a flight, such as the departure and arrival times, flight number, and airline name. It is commonly used in travel websites and applications to provide users with relevant information about their flights.

Why use Tailwind CSS to create a Flight Card UI component?

Tailwind CSS provides a set of pre-defined CSS classes that can be used to style HTML elements. This makes it easy for developers to create custom designs without writing CSS from scratch. Additionally, Tailwind CSS is highly customizable, which means developers can easily modify the existing styles to match their design requirements.

The preview of Flight Card UI component

To create a Flight Card UI component, we will use Tailwind CSS to style the HTML elements. The Flight Card UI component will consist of a card container with the flight information displayed inside. Here is a preview of what the final Flight Card UI component will look like:

Free download of the Flight Card's source code

The source code of Flight Card UI component

To create the Flight Card UI component, we will use HTML and Tailwind CSS. The HTML code will define the structure of the Flight Card, while the Tailwind CSS classes will style the HTML elements. Here is the source code for the Flight Card UI component:

<div class="p-10">
  <div class="max-w-full  bg-white flex flex-col rounded overflow-hidden shadow-lg">
    <div class="flex flex-row items-baseline flex-nowrap bg-gray-100 p-2">
      <svg viewBox="0 0 64 64" data-testid="tripDetails-bound-plane-icon" pointer-events="all" aria-hidden="true" class="mt-2 mr-1" role="presentation" style="fill: rgb(102, 102, 102); height: 0.9rem; width: 0.9rem;">
        <path d="M43.389 38.269L29.222 61.34a1.152 1.152 0 01-1.064.615H20.99a1.219 1.219 0 01-1.007-.5 1.324 1.324 0 01-.2-1.149L26.2 38.27H11.7l-3.947 6.919a1.209 1.209 0 01-1.092.644H1.285a1.234 1.234 0 01-.895-.392l-.057-.056a1.427 1.427 0 01-.308-1.036L1.789 32 .025 19.656a1.182 1.182 0 01.281-1.009 1.356 1.356 0 01.951-.448l5.4-.027a1.227 1.227 0 01.9.391.85.85 0 01.2.252L11.7 25.73h14.5L19.792 3.7a1.324 1.324 0 01.2-1.149A1.219 1.219 0 0121 2.045h7.168a1.152 1.152 0 011.064.615l14.162 23.071h8.959a17.287 17.287 0 017.839 1.791Q63.777 29.315 64 32q-.224 2.685-3.807 4.478a17.282 17.282 0 01-7.84 1.793h-9.016z"></path>
      </svg>
      <h1 class="ml-2 uppercase font-bold text-gray-500">departure</h1>
      <p class="ml-2 font-normal text-gray-500">Wednesday 18 Aug</p>
    </div>
    <div class="mt-2 flex justify-start bg-white p-2">
      <div class="flex mx-2 ml-6 h8 px-2 flex-row items-baseline rounded-full bg-gray-100 p-1">
        <svg viewBox="0 0 64 64" pointer-events="all" aria-hidden="true" class="etiIcon css-jbc4oa" role="presentation" style="fill: rgb(102, 102, 102); height: 12px; width: 12px;">
          <path d="M43.389 38.269L29.222 61.34a1.152 1.152 0 01-1.064.615H20.99a1.219 1.219 0 01-1.007-.5 1.324 1.324 0 01-.2-1.149L26.2 38.27H11.7l-3.947 6.919a1.209 1.209 0 01-1.092.644H1.285a1.234 1.234 0 01-.895-.392l-.057-.056a1.427 1.427 0 01-.308-1.036L1.789 32 .025 19.656a1.182 1.182 0 01.281-1.009 1.356 1.356 0 01.951-.448l5.4-.027a1.227 1.227 0 01.9.391.85.85 0 01.2.252L11.7 25.73h14.5L19.792 3.7a1.324 1.324 0 01.2-1.149A1.219 1.219 0 0121 2.045h7.168a1.152 1.152 0 011.064.615l14.162 23.071h8.959a17.287 17.287 0 017.839 1.791Q63.777 29.315 64 32q-.224 2.685-3.807 4.478a17.282 17.282 0 01-7.84 1.793h-9.016z"></path>
        </svg>
        <p class="font-normal text-sm ml-1 text-gray-500">Economy</p>
      </div>
    </div>
    <div class="mt-2 flex sm:flex-row mx-6 sm:justify-between flex-wrap ">
      <div class="flex flex-row place-items-center p-2">
        <img alt="Qatar Airways" class="w-10 h-10" src="data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kV7l8SNyDC5WYkoamU5YcF6re3HgOjPzGvurzCmag8FnCKFujtBlsOKXoOW9hZWViLLOEca5fe0xPRAhWrKBGgU9338JsNYDyv02+Pm/aZaLeLuGrfOSZ8EKZvwHV+ro3h8gwQjPMDfbPh3IrPYtnLMctTrSSm2usWbg1lMX/hQgRgM+OL+ShNS5MpPrWg2l4O7RBQ/f2ajsQfXCj7XVLLed7NMoVc86BTs5dTxLCkXSLMd3pBwvVta9nX3JJJto21z346W4Fw0oDFN6D8x0o4MzRxMvTW6Te/c/qA0iycbbHT5KfI6Qhm/nzAN5nZm01ai4Xwu9k257+azjz4wShulIc8FF8TtSOUrIt+bwNl+aId7k5joM6db7LmawL0nYlrWJgGw7F56AOGLzyFt0dIrCfsgfoi3Wc2IeL6up5Vsrh29BwgJS4ZXiYanrhlX4tWHnGu4fPJ9e7tswxbKYzR6RkSw1al91StX+vWWfwS+0p3gZUU2rn00A67rrTj4g0M7WkThyoF3GTBLNpld/8B19jIDAbtY4Nu/8mC2XZ4VabcZC8eLKkwthP3VVzIiDLfFvOGPA4MhXBebhTqsq7/5AKeUu8AxvluM+turc6teywn/oSdp3jXK6Qvdn/Lg/i8DHKfbg+UHUQAAAABJRU5ErkJggg==" style="opacity: 1; transform-origin: 0% 50% 0px; transform: none;" />
        <div class="flex flex-col ml-2">
          <p class="text-xs text-gray-500 font-bold">Qatar Airways</p>
          <p class="text-xs text-gray-500">QR1456</p>
          <div class="text-xs text-gray-500">2*23kg</div>
        </div>
      </div>

      <div class="flex flex-col p-2">
        <p class="font-bold">18:25</p>
        <p class="text-gray-500"><span class="font-bold">HRE</span> Harare</p>
        <p class="text-gray-500">Zimbabwe</p>
      </div>
      <div class="flex flex-col flex-wrap p-2">
        <p class="font-bold">19:25</p>
        <p class="text-gray-500"><span class="font-bold">LUN</span> Lusaka</p>
        <p class="text-gray-500">Zambia</p>
      </div>
    </div>
    <div class="mt-4 bg-gray-100 flex flex-row flex-wrap md:flex-nowrap justify-between items-baseline">
      <div class="flex mx-6 py-4 flex-row flex-wrap">
        <svg class="w-12 h-10 p-2 mx-2 self-center bg-gray-400 rounded-full fill-current text-white" viewBox="0 0 64 64" pointer-events="all" aria-hidden="true" role="presentation"><path d="M43.389 38.269L29.222 61.34a1.152 1.152 0 01-1.064.615H20.99a1.219 1.219 0 01-1.007-.5 1.324 1.324 0 01-.2-1.149L26.2 38.27H11.7l-3.947 6.919a1.209 1.209 0 01-1.092.644H1.285a1.234 1.234 0 01-.895-.392l-.057-.056a1.427 1.427 0 01-.308-1.036L1.789 32 .025 19.656a1.182 1.182 0 01.281-1.009 1.356 1.356 0 01.951-.448l5.4-.027a1.227 1.227 0 01.9.391.85.85 0 01.2.252L11.7 25.73h14.5L19.792 3.7a1.324 1.324 0 01.2-1.149A1.219 1.219 0 0121 2.045h7.168a1.152 1.152 0 011.064.615l14.162 23.071h8.959a17.287 17.287 0 017.839 1.791Q63.777 29.315 64 32q-.224 2.685-3.807 4.478a17.282 17.282 0 01-7.84 1.793h-9.016z"></path></svg>
        <div class="text-sm mx-2 flex flex-col">
          <p class="">Standard Ticket</p>
          <p class="font-bold">$404.73</p>
          <p class="text-xs text-gray-500">Price per adult</p>
        </div>
        <button class="w-32 h-11 rounded flex border-solid border bg-white mx-2 justify-center place-items-center"><div class="">Book</div></button>
      </div>
      <div class="md:border-l-2 mx-6 md:border-dotted flex flex-row py-4 mr-6 flex-wrap">
        <svg class="w-12 h-10 p-2 mx-2 self-center bg-green-800 rounded-full fill-current text-white" viewBox="0 0 64 64" pointer-events="all" aria-hidden="true" class="etiIcon css-ecvhkc" role="presentation" style="fill: rgb(255, 255, 255);"><path d="M62.917 38.962C59.376 53.71 47.207 64 31.833 64a31.93 31.93 0 01-21.915-8.832l-5.376 5.376a2.65 2.65 0 01-1.874.789A2.685 2.685 0 010 58.668V40a2.687 2.687 0 012.667-2.667h18.666A2.687 2.687 0 0124 40a2.645 2.645 0 01-.793 1.877L17.5 47.58a21.244 21.244 0 0032.665-4.414 33.706 33.706 0 002.208-4.873 1.292 1.292 0 011.25-.96h8a1.342 1.342 0 011.333 1.337.738.738 0 01-.041.293M64 24a2.687 2.687 0 01-2.667 2.668H42.667A2.687 2.687 0 0140 24a2.654 2.654 0 01.793-1.877l5.749-5.746a21.336 21.336 0 00-32.706 4.457 33.224 33.224 0 00-2.208 4.873 1.293 1.293 0 01-1.25.96H2.085A1.342 1.342 0 01.752 25.33v-.293C4.334 10.247 16.626 0 32 0a32.355 32.355 0 0122.041 8.832l5.419-5.376a2.644 2.644 0 011.872-.789A2.685 2.685 0 0164 5.333z"></path></svg>
        <div class="text-sm mx-2 flex flex-col">
          <p>Flexible Ticket</p>
          <p class="font-bold">$605.43</p>
          <p class="text-xs text-gray-500">Price per adult</p>
        </div>
        <button class="w-32 h-11 rounded flex border-solid border text-white bg-green-800 mx-2 justify-center place-items-center"><div class="">Book</div></button>
      </div>
    </div>
  </div>
</div>

How to create a Flight Card with Tailwind CSS?

To create a Flight Card UI component with Tailwind CSS, follow these steps:

Step 1: Set up the HTML structure

The first step is to set up the HTML structure for the Flight Card. We will use a div element with the class name "flight-card" to create the card container. Inside the card container, we will add the flight information, such as the departure and arrival times, flight number, and airline name.

<div class="flight-card">
  <div class="flight-info">
    <div class="flight-time">10:00 AM - 12:00 PM</div>
    <div class="flight-number">Flight Number: AC1234</div>
    <div class="flight-airline">Airline: Air Canada</div>
  </div>
</div>

Step 2: Style the card container

The next step is to style the card container using Tailwind CSS classes. We will use the "bg-white", "rounded-lg", "shadow-md", and "p-4" classes to give the card container a white background, rounded corners, a shadow effect, and padding.

<div class="flight-card bg-white rounded-lg shadow-md p-4">
  <div class="flight-info">
    <div class="flight-time">10:00 AM - 12:00 PM</div>
    <div class="flight-number">Flight Number: AC1234</div>
    <div class="flight-airline">Airline: Air Canada</div>
  </div>
</div>

Step 3: Style the flight information

The final step is to style the flight information using Tailwind CSS classes. We will use the "text-gray-700", "font-bold", and "mb-2" classes to give the flight information a dark gray color, bold font, and margin-bottom.

<div class="flight-card bg-white rounded-lg shadow-md p-4">
  <div class="flight-info">
    <div class="flight-time text-gray-700 font-bold mb-2">10:00 AM - 12:00 PM</div>
    <div class="flight-number text-gray-700 mb-2">Flight Number: AC1234</div>
    <div class="flight-airline text-gray-700 mb-2">Airline: Air Canada</div>
  </div>
</div>

Conclusion

In this article, we have explored how to create a Flight Card UI component using Tailwind CSS. We have discussed the benefits of using Tailwind CSS and provided a step-by-step guide on how to create a Flight Card UI component. With this knowledge, you can now create your own custom UI components using Tailwind CSS.