简体   繁体   中英

Navbar shrinking with fixed position

I'm using tailwind-css in my svelte app. Why does the following navbar shrink when I set the position to fixed?

 <nav class="container left-0 top-0 w-full bg-white"> <div class="flex"> <!-- navbar elements --> </div> </nav>

无固定位置

With

 <nav class="container fixed left-0 top-0 w-full bg-white">

在此处输入图像描述

The issue is likely the use of the container class, not the fixed class.

In TailwindCSS, container is used for constraining an elements width to the width of the current breakpoint.

在此处输入图像描述

https://tailwindcss.com/docs/container

So let's say your screen is currently 1200px wide. The container will always be 1024px wide—even if you set w-full . Because the max width in the large breakpoint is 1024px.

When you update the size to max-w-full , you're essentially removing this constraint on the size, letting the nav span the full width of the screen. Adding the max-w-full class cancels out the container class. So you can actually get the same result if you remove both the container and max-w-full classes.

I managed to solve it by modifying class w-full to max-w-full, although I'm not sure exactly why it made so much of a difference

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