twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
169.99k stars 78.74k forks source link

“Sticky” content overlaps dropdown menus #31747

Open martinbean opened 3 years ago

martinbean commented 3 years ago

“Sticky” content (using the .sticky-top class for example) overlap dropdown menus. This doesn’t make sense, has been raised before (#28569, #28590, #28926) without any explanation, other than a shoot-down about not rearranging the z-index scale because it’s been like that for however long.

Sorry, but having “sticky” content slide over dropdown menus doesn’t make any sense, whatsoever. So what is the actual rationale for leaving it like this and not even considering fixing it?

mdo commented 3 years ago

The z-index scale is indeed designed with a particular layering system in mind. Some of this is mentioned at https://v5.getbootstrap.com/docs/5.0/layout/z-index/. And I'm including it here for context.

$zindex-dropdown:                   1000 !default;
$zindex-sticky:                     1020 !default;
$zindex-fixed:                      1030 !default;
$zindex-modal-backdrop:             1040 !default;
$zindex-modal:                      1050 !default;
$zindex-popover:                    1060 !default;
$zindex-tooltip:                    1070 !default;

Reiterating it here, early on for Bootstrap, we created a set of layers in which our UI operates.

So, which of those layers aren't right or are causing the most issues? A demo could help us look at things a bit differently, but if memory serves, to date this layering system has worked quite well overall.

martinbean commented 3 years ago

@mdo So where I’ve ran into this issue is with a “sticky” sidebar content card on a page that also has dropdown menus. I’d expect the dropdown menus to be on top of any sticky content; I don’t see why sticky content should be in front of a dropdown menu a user’s triggered? It just looks… bizarre and not at all what I‘d expect.

Screenshot 2020-09-25 at 21 46 17

mdo commented 3 years ago

That's more than fair, I get that issue. I think sticky content wasn't on our minds because we were look at is like sticky navigation in the form of navbars and what not. This is definitely a use case we should account for and would require a z-index update in v5. Not sure what we could do about v4 though.

martinbean commented 3 years ago

@mdo Cool 🙂

I’m currently overriding the z-indexes in my own project to work around this, but wanted to raise it as it does seem to go against expectations. But I can understand it might get complicated with sticky navbars with dropdowns (where the dropdown needs a higher z-index than the sticky navbar) but then sticky content (like in the example above) that should sit underneath. Maybe the z-index hierarchy should go like this (highest to lowest):

  1. Dropdowns (always on top of “sticky” elements, be them navbars or content as per my example).
  2. Sticky navbars (so they are always above sticky content).
  3. Sticky content, such as the sticky sidebar content example.
iatek commented 3 years ago

I've ran in to this same issue with Dropdowns. IMO, Dropdown should be a higher z-index than both sticky and fixed. For example, I'm currently dealing with a scenario where a Dropdown inside a Navbar needs to overlay a sticky sidebar but it's hidden behind: https://codeply.com/p/w5ZxAjmjpo

leecollings-sb commented 2 years ago

Just pointing out we're at v5.1.3 now and this issue is still here and hasn't been addressed at all. Looks absolutely awful to have dropdown menus in navigation not visible because of a sticky sidebar on the page.

Just swap the dropdown and sticky z-index values around, and it's fixed. What's the hold up?

mdo commented 2 years ago

Just pointing out we're at v5.1.3 now and this issue is still here and hasn't been addressed at all. Looks absolutely awful to have dropdown menus in navigation not visible because of a sticky sidebar on the page.

Just swap the dropdown and sticky z-index values around, and it's fixed. What's the hold up?

Consider the context. We have a two year old thread with a couple of people discussing a change. No other issues reporting it. That tells me that, most likely, very few people are running into this issue. It also tells me it's low priority compared to other changes I could be putting my time and effort into.

If you really want this change, do the leg work and open a PR. Test out the various situations with how sticky helpers and fixed utilities affect not only one another, but our various components, too.

Or, wait for me to come back to this when I have time and not as many other higher priority issues and PRs :).

vctormb commented 1 year ago

@mdo Cool 🙂

I’m currently overriding the z-indexes in my own project to work around this, but wanted to raise it as it does seem to go against expectations. But I can understand it might get complicated with sticky navbars with dropdowns (where the dropdown needs a higher z-index than the sticky navbar) but then sticky content (like in the example above) that should sit underneath. Maybe the z-index hierarchy should go like this (highest to lowest):

  1. Dropdowns (always on top of “sticky” elements, be them navbars or content as per my example).
  2. Sticky navbars (so they are always above sticky content).
  3. Sticky content, such as the sticky sidebar content example.

What do you all think about this order?

$zindex-sticky 1000;
$zindex-fixed: 1010; // <- don't know why the second item was 1020. I just changed to `10`
$zindex-offcanvas-backdrop: 1020;
$zindex-offcanvas: 1025;
$zindex-modal-backdrop: 1030;
$zindex-modal: 1035;
$zindex-popover: 1040;
$zindex-dropdown: 1050; // <- dropdown above popover and modal as well
$zindex-toast: 1060;
$zindex-tooltip: 1070; // <- tooltip above toast
uecasm commented 1 year ago

My recommended change to the Bootstrap 5.1 order is only to move dropdown:

$zindex-dropdown: 1060;

This puts it above all the "background" elements (sticky, fixed, offcanvas, modal) but below all the "popup" elements (toast, popover, tooltip), which seems like the best place to me. Or rather, the dropdown is the lowest-priority popup.

The justification above for "dropdown" being a low value doesn't make much sense to me -- while it's true that the button/link are usually inside navs and should be considered "background", that's not true of the dropdown menu itself, which is what this z-index is applied to. That should always be on top of page content, even when opened from a background nav (or a sticky/offcanvas nav).

FWIW, I ran into this after making a sticky table header, which is another thing that Bootstrap doesn't support very well out of the box.

leecollings-sb commented 1 year ago

This puts it above all the "background" elements (sticky, fixed, offcanvas, modal) but below all the "popup" elements (toast, popover, tooltip)

@uecasm I'm not sure a modal is a background element, it's the same as a popover or tooltip. I think the dropdown menus should be behind modals (these should be in front of pretty much everything when they're active).

I think by just putting the sticky items at the lowest of the layers, should probably be enough to correct most issues, unless I'm wrong.

But anyway, having just read back over this thread, I'd like to apologise to @mdo as I can see my comment was particularly rude.

uecasm commented 1 year ago

My argument for "modal as background" is that if there are background navs (or forms, or other content) with dropdowns open, those dropdowns should be closed when the modal opens. Meanwhile, the modal itself might contain dropdowns of its own, that should appear in front of the modal.

A dropdown (or more precisely, the menu part of it) is an ephemeral foreground element -- it's only open temporarily while you're paying attention to it, and once attention shifts somewhere else it should go away. But the menu items themselves might still have popovers or tooltips, hence those needing to be higher priority.

AlexDanault commented 1 year ago

I think by just putting the sticky items at the lowest of the layers, should probably be enough to correct most issues

I agree with this.

DmitriIV100 commented 1 year ago

I would like to express my support for bringing the dropdown-menu z-index above that of sticky-top

image

leecollings-sb commented 1 year ago

It does make most sense to put the sticky items at the bottom of the level, as that would resolve all of these issues. Hopefully it will be implemented in an update soon?

acocheo commented 5 months ago

Same issue here. Dropdowns are generated by an interaction, they should always go over fixed and sticky elements, that often are simply part of page content

VladStulikov commented 3 months ago

Sams issue here: image

dailytabs commented 1 week ago

Using a sticky save button at the bottom of the vp. Drop-downs don't account for this height being used up and will gladly draw underneath it (as height gets even smaller, the drop-down switches to opening upwards and is no longer an issue).

A simple global override of $zindex-dropdown fixes it if you use a different layering strategy.

For me, I never want a type-ahead drop-down under an input to overlap...anything, really - it should stay in its form/container. I would rather CSS/bootstrap be smart enough to avoid it and switch to upwards sooner. That doesn't work for everyone, though (the OP wanted their drop-down to be above the sticky content, not avoid it). Given the complexity combined with the "fix" being setting one variable, not really sure this is impactful enough to be worth resolving.