Published on

6 Steps To Create A Game Lobby With Tailwind CSS Like A Pro In Under An Hour

Game Lobby

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 Game Lobby ui component

Inspired by a game called "party animals" that have a fantastic ui

Why use Tailwind CSS to create a Game Lobby ui component?

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

The preview of Game Lobby ui component

Free download of the Game Lobby's source code

The source code of Game Lobby ui component

<div class="min-h-screen flex-1 bg-gray-200 p-4 flex justify-center items-center">
<div class="bg-white w-full md:max-w-4xl rounded-lg shadow">
<div class="h-12 flex justify-between items-center border-b border-gray-200 m-4">
  <div >
   <div class="text-xl font-bold text-gray-700">Josef256 Lobby</div>
   <div class="text-sm font-base text-gray-500">Waiting for more players...</div>
  </div>
  <div>
    <div class="flex items-center justify-center w-full  shadow-md rounded-full">
      <label
          htmlFor="toogleA"
          class="flex items-center cursor-pointer"
      >
        <div class="flex items-center">
          <input id="toogleA" type="checkbox" class="hidden"/>
          <div
              class="toggle__line w-20 h-10 bg-gray-300 rounded-full shadow-inner"
          >
          </div>
          <div
              class="toggle__dot bg-red-400 absolute w-10 h-10 bg-white rounded-full shadow flex items-center justify-center"
          >
            <svg class="text-white w-6 h-6 " xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z" />
            </svg>
          </div>
        </div>
      </label>
    </div>
  </div>
</div>
<div class="px-6">
  <div class="flex justify-between items-center h-16 p-4 my-6  rounded-lg border border-gray-100 shadow-md">
    <div class="flex items-center">
      <img class="rounded-full h-12 w-12" src="https://static-cdn.jtvnw.net/jtv_user_pictures/27fdad08-a2c2-4e0b-8983-448c39519643-profile_image-70x70.png" alt="Logo" />
    <div class="ml-2">
      <div class="text-sm font-semibold text-gray-600">Lirik</div>
      <div class="text-sm font-light text-gray-500">Level 6 - Warlock</div>
    </div>
    </div>
    <div>
      <button class="bg-red-400 hover:bg-red-500 p-2 rounded-full shadow-md flex justify-center items-center">
        <svg class="text-white toggle__lock w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
        </svg>
      </button>
    </div>
  </div>
  <div class="flex justify-between items-center h-16 p-4 my-6  rounded-lg border border-gray-100 shadow-md">
    <div class="flex items-center">
      <img class="rounded-full h-12 w-12" src="https://static-cdn.jtvnw.net/jtv_user_pictures/cb661e9a-68e5-4e37-89ce-231960ff7f8e-profile_image-70x70.png" alt="Logo" />
      <div class="ml-2">
        <div class="text-sm font-semibold text-gray-600">MembTV</div>
        <div class="text-sm font-light text-gray-500">Level 4 - Monk</div>
      </div>
    </div>
    <div>
      <button class="bg-red-400 hover:bg-red-500  p-2 rounded-full shadow-md flex justify-center items-center">
        <svg class="text-white toggle__lock w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
        </svg>
      </button>
    </div>
  </div>
  <div class="flex justify-between items-center h-16 p-4 my-6  rounded-lg border border-gray-100 shadow-md">
    <div class="flex items-center">
      <img class="rounded-full h-12 w-12" src="https://static-cdn.jtvnw.net/jtv_user_pictures/e82b2c90-efe6-41c7-bd50-7caba86fd3b5-profile_image-70x70.png" alt="Logo" />
      <div class="ml-2">
        <div class="text-sm font-semibold text-gray-600">DansGaming</div>
        <div class="text-sm font-light text-gray-500">Level 12 - Paladan</div>
      </div>
    </div>
    <div>
      <button class="bg-red-400 hover:bg-red-500  p-2 rounded-full shadow-md flex justify-center items-center">
        <svg class="text-white toggle__lock w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
        </svg>
      </button>
    </div>
  </div>
  <div class="flex bg-gray-200 justify-center items-center h-16 p-4 my-6  rounded-lg  shadow-inner">
    <div class="flex items-center border border-gray-400 p-2 border-dashed rounded cursor-pointer">
    <div>
      <svg class="text-gray-500 w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
      <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
    </svg>
    </div>
      <div class="ml-1 text-gray-500 font-medium"> Invite a friend</div>
    </div>
  </div>
</div>
  <div class="p-6 ">
    <button class="p-4 bg-green-400 hover:bg-green-500 w-full rounded-lg shadow text-xl font-medium uppercase text-white">Start the game</button>
  </div>
</div>
    </div>

<style>
  .toggle__dot {
    transition: all 0.3s ease-in-out;
}

input:checked ~ .toggle__dot {
    transform: translateX(100%);
    background-color:#68D391
}
</style>

How to create a Game Lobby with Tailwind CSS?

Install tailwind css of verion 1.7.0

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

<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">

All the unility class needed to create a Game Lobby component

  • min-h-screen
  • flex-1
  • bg-gray-200
  • p-4
  • flex
  • bg-white
  • w-full
  • md:max-w-4xl
  • h-12
  • border-b
  • border-gray-200
  • m-4
  • text-xl
  • text-gray-700
  • text-sm
  • text-gray-500
  • hidden
  • w-20
  • h-10
  • bg-gray-300
  • bg-red-400
  • absolute
  • w-10
  • text-white
  • w-6
  • h-6
  • px-6
  • h-16
  • my-6
  • border-gray-100
  • w-12
  • ml-2
  • text-gray-600
  • hover:bg-red-500
  • p-2
  • border-gray-400
  • border-dashed
  • ml-1
  • p-6
  • bg-green-400
  • hover:bg-green-500

41 steps to create a Game Lobby component with Tailwind CSS

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

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

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

  4. Control the padding on all sides of an element to 1rem using the p-4 utilities.

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

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

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

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

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

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

  11. Control the border color of an element to gray-200 using the border-gray-200 utilities.

  12. Control the margin on all sides of an element to 1rem using the m-4 utilities.

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

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

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

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

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

  18. Use w-20 to set an element to a fixed width(5rem).

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

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

  21. Control the background color of an element to red-400 using the bg-red-400 utilities.

  22. 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.

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

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

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

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

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

  28. Use h-16 to set an element to a fixed height(4rem).

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

  30. Control the border color of an element to gray-100 using the border-gray-100 utilities.

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

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

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

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

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

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

  37. Control the border color of an element to dashed using the border-dashed utilities.

  38. Control the margin on left side of an element to 0.25rem using the ml-1 utilities.

  39. Control the padding on all sides of an element to 1.5rem using the p-6 utilities.

  40. Control the background color of an element to green-400 using the bg-green-400 utilities.

  41. 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 create a Game Lobby components, learn and follow along to implement your own components.