Home > front end >  How to center flex child based on parent width
How to center flex child based on parent width

Time:12-22

I am trying to center the nav menu horizontally based on header tags width using tailwind. Problem is that it only centers based on the nav tags width.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
    <script src="https://cdn.tailwindcss.com"></script>
  </head>
  <body>
    <header >
      <div >
        <img src="https://picsum.photos/500/100" alt=""  />
        <span>Company Name</span>
      </div>
      <nav
        
      >
        <a href="#">Home</a>
        <a href="#">Search</a>
      </nav>
      <div>
        Profile
      </div>
    </header>
  </body>
</html>

CodePudding user response:

Like this? I added relative on <header> and absolute w-full on <nav>.

<header >
  <div >
    <img src="https://picsum.photos/500/100" alt=""  />
    <span>Company Name</span>
  </div>
  <nav >
    <a href="#">Home</a>
    <a href="#">Search</a>
  </nav>
  <div>
    Profile
  </div>
</header>
  • Related