backdrop-issues icon indicating copy to clipboard operation
backdrop-issues copied to clipboard

Clicking hashtag links scroll too far

Open alanmels opened this issue 2 years ago • 5 comments

Description of the bug

With the Administration Bar module disabled clicking on such links you can see at least the part of the relevant content:

Screenshot 2022-11-15 at 3 39 44 PM

However, Backdrop comes with Administration Bar module enabled and it remains enabled on most of the websites, so clicking the same link takes you too far and you are not able to see relevant content at all. You would have to scroll little bit up to see the right content:

Screenshot 2022-11-15 at 4 01 46 PM

Expected behavior

Ideally, you should be able to see not only the part of the relevant content, but all of it including the title like so:

Screenshot 2022-11-15 at 3 56 25 PM

I see from various publications like, for example, https://css-tricks.com/hash-tag-links-padding/ it's a common browser issue. However, Backdrop's Administration Bar module is making it even worse. I am not sure what's the ideal solution here, so suggestions are welcome.

alanmels avatar Nov 15 '22 22:11 alanmels

Good point! Inspired by the CSS tricks article, I've added the following styles via CSS Injector on top of the Seven theme of a test site. What do you think of it?

#permissions td.module:target {
  padding-top:51px;
  background: #ffe082;
}
.admin-bar #permissions td.module:target {
  padding-top:84px;
}

The background isn't necessary but helps with testing (and may even be a general enhancement).

olafgrabienski avatar Nov 16 '22 13:11 olafgrabienski

Screenshot based on the CSS fix:

backdrop-permissions-css-fix

olafgrabienski avatar Nov 16 '22 13:11 olafgrabienski

There's an alternate solution for that - scroll-margin-top:

.admin-bar :target {
  scroll-margin-top: 34px;
}

Browser support is good nowadays: https://caniuse.com/mdn-css_properties_scroll-margin-top

indigoxela avatar Nov 16 '22 15:11 indigoxela

I believe the solution should not be specifically for the Permissions page as the problem persists anywhere, take for example https://sandbox.ddev.site/admin/modules#module-comment. Not sure what's the ideal solution, but I really like @olafgrabienski's idea of making the target section outstanding by changing the background color.

I'm just afraid there would be too many css rules if we are to specify each possible target, so ideally some kind of universal solution for any link with anchor be found, maybe including a new jquery condition rule.

alanmels avatar Nov 16 '22 20:11 alanmels

I believe the solution should not be specifically for the Permissions page ...

Agreed, a more general approach is preferable, but wouldn't work for the background. (The Permissions page seems however more important to me, as its anchors are linked from the Modules page's dropbuttons. Also, the background could be a follow-up.)

@indigoxela, unfortunately your (more general) approach with scroll-margin-top doesn't work for me, it doesn't change the position of the target element when I jump to it using an anchor link.

olafgrabienski avatar Nov 16 '22 21:11 olafgrabienski