Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind center an absolute element

I want to create a little login pop-up card at the middle of the page when the client presses the login button. I managed to create the card itself, a gave it .absolute z-10 to be at the top of the other contents. I also wrapped it inside a container div with .relative to be able to position the card. My problem is I can't position it to the middle. If I add for example .right-0 it works, but I want to position it in the middle and I couldn't find anything in the documentation about that... Also, how can I add more height to my card that 64?

My code:

index.html

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Jófogás</title>
    <link
      href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
      rel="stylesheet"
    />
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
    />
  </head>
  <body>
    <!-- header section -->
    <header class="bg-white flex">
      <div class="w-3/6">
        <img
          class="h-12 m-4"
          src="./logo_img/jofogas_logo_original.jpg"
          alt="jofogas_logo_original"
        />
      </div>
      <div class="mx-6 my-6 w-3/6 text-right">
        <button class="bg-orange-500 rounded py-2 px-4 text-white">
          Belépés
        </button>
      </div>
    </header>
    <!-- login card -->
    <div class="relative">
      <div class="absolute z-10 items-center right-0">
        <div
          id="login-card"
          class="w-56 h-64 text-center bg-orange-500 rounded-lg"
        ></div>
      </div>
    </div>
    <!-- search bar -->
    <div class="bg-gray-200 rounded-lg mx-10 md:pt-10" id="search-container">
      <div class="text-center text-4xl hidden md:block" id="main-text">
        Hirdess vagy vásárolj a Jófogáson!
      </div>
      <div class="py-10 text-center">
        <input
          class="w-5/6 md:w-3/6 md:h-12"
          id="search-bar"
          type="text"
          placeholder="Mit keresel?"
        />
        <i class="fa fa-search icon"></i>
      </div>
    </div>
    <div class="text-center">
      <button
        class="bg-green-500 rounded py-4 px-8 md:py-8 md:px-16 text-white text-xl md:text-2xl my-10"
      >
        Hirdetésfeladás
      </button>
    </div>
  </body>
</html>
like image 516
Frigyes Vass Avatar asked Dec 18 '22 12:12

Frigyes Vass


1 Answers

Try this:

<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
    ...
</div>
like image 60
Amir Rami Avatar answered Jan 05 '23 16:01

Amir Rami