简体   繁体   中英

Fixed width sidebar isn't the right size in Tailwind CSS

I have this simple HTML and I am using tailwindcss .

<!DOCTYPE html>
<html class="h-full" 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 class="h-full">
    <div id="app" class="h-full flex">
      <div class="w-[312px] bg-red-100">
        <h1 class="text-3xl font-bold">
          Sidebar
        </h1>
      </div>
      <div class="w-full bg-green-100">
        <h1 class="text-3xl font-bold">
          Main
        </h1>
      </div>
    </div>
  </body>
</html>

For some reason, my sidebar's width is not 312px like I want it to be.

截屏

What am I missing? Here is a CodeSandbox too .

Just add flex-none to prevent div from growing and shrinking. Like that.

 <div class="w-[312px] flex-none bg-red-100">
     <h1 class="text-3xl font-bold">
          Sidebar
    </h1>
 </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM