Problem/Motivation

Currently Toolbar is adding a 20px padding to the <body> tag to compensate its height, but it makes the anchors to point 20px away so they end up hidden under the Toolbar.

Proposed resolution

http://stackoverflow.com/a/21707103

Something like this may work:

:target:before {
    display: block;    
    position: relative;     
    top: -100px;
    visibility: hidden;
}

Remaining tasks

Manually test it

Comments

ckrina created an issue. See original summary.

joelpittet’s picture

Issue summary: View changes
Issue tags: +Novice, +Dublin2016

I've added a proposed solution

ckrina’s picture

nod_’s picture

Ehud’s picture

Matthew Lambert and me are handling this Dublin2016 (:

aburrows’s picture

@Ehud can you assign this to you

Ehud’s picture

Assigned: Unassigned » Ehud
Ehud’s picture

Assigned: Ehud » Unassigned
Issue tags: -Novice

Looks like the proposed solution doesn't work. I applied it and played with it.. So probably javascript will do it.

nod_’s picture

Status: Active » Needs review
nod_’s picture

Status: Needs review » Active
chrisrockwell’s picture

I think @joelpittet's solution will work with some tweaking. Something like this:

.toolbar-fixed :target:before {
  content: "";
  display: block;
  height: 79px; /* height given to toolbar */
  margin-top: -79px;
}
.toolbar-vertical :target:before {
  height: 39px; /* height given to toolbar */
  margin-top: -39px;
}

I don't see how we get away *without* using some specificity as we can't just simply use :target:before as it will affect users without access to the toolbar.

I'd submit a patch, but someone will need to tell me where this code should go :).

chrisrockwell’s picture

Making this a new comment to see the diff, but I like this better as it accounts for:

  1. Toolbar tray closed
  2. Toolbar open horizontally
  3. Toolbar open vertically
.toolbar-fixed :target:before {
  content: "";
  display: block;
  height: 39px; /* Amount of padding toolbar gives to body */
  margin-top: -39px;
}
.toolbar-horizontal.toolbar-tray-open :target:before {
  height: 79px; /* Amount of padding toolbar gives to body when the tray is open horizontally */
  margin-top: -79px;
}
joelpittet’s picture

@chrisrockwell totally agree, it needs to target the toolbar! Could you make a patch for that and we can find someone to test it out?

chrisrockwell’s picture

Attaching #12 as a patch. Do we need two separate patches for Stable and core/modules/toolbar? Or - maybe we can remove toolbar.module.css from Stable since it appears to be an exact copy?

chrisrockwell’s picture

Status: Active » Needs review
joelpittet’s picture

Issue tags: +Needs manual testing

I'm still unsure how to deal with bugs in CSS and Stable... it would be nice to have a clear way to make that call from the Stable subsystem maintainers. For now I think having them together is good until deemed appropriate to split.

Marking for manual testing for someone to review, test if it works and mark this RTBC if so. Thanks for the patch @chrisrockwell

davidhernandez’s picture

Unless there is an argument beyond "don't touch Stable" I think we should be able to do this. It is a bug fix applied to a sudo selector. It only affects the toolbar, which is an administrative element, and doesn't affect its actual internal styling.

Manual testing for sure, and test on a theme other than Seven. I would test with Stable, Stark (which doesnt use Stable), and another.

maybe we can remove toolbar.module.css from Stable since it appears to be an exact copy?

No, that is its purpose, to be a copy. If we have to, we can make these changes to the core toolbar CSS and not touch the Stable CSS. The easy fix then becomes to remove the Stable CSS in your theme and reimplement the core toolbar one. We could actually do that with Seven.

kpaxman’s picture

My comment is speculative, since I haven't had the opportunity to test the actual patch.

I used to run a JavaScript solution for this in D7, since the height of the toolbar could vary as it wrapped menu items to the next line as needed. The D8 toolbar is a fixed height, since you're using pixel units? What if someone changes the font size?

joelpittet’s picture

@kpaxman, you are right, we should at least put rem values in there like we do with other pixel values.

We could use JS and listen to the same events and just read the body padding-top values. Was hoping for CSS for a the simplicity of it.
The body padding is set here: Drupal.toolbar.BodyVisualView

Or maybe instead of listening to the events we could listen to body changes with mutation observers?
http://caniuse.com/#feat=mutationobserver

Here's a prototype of something that could work:
https://jsfiddle.net/91w05w58/1/

I noticed we've been ignoring IE9 and IE10 recently to some extent but there are polyfills for this if need be.

chrisrockwell’s picture

I've been considering this as a JS only solution (which is reasonable since it's the toolbar). What about this patch that adds a style tag and just lets the toolbar manage the height and negative margin? I'm assuming this could be moved into Seven's js if it cant' go into toolbar.

From my testing, this addresses @kpaxman's concern.

chrisrockwell’s picture

I've doing a lot of research into this, and discussing with @joelpittet, and I'm coming to the conclusion that, IMHO, this isn't the responsibility of toolbar. What about adding some css to stable and classy?

Bootstrap accounts for the toolbar by hard-coding the values:

body.toolbar-fixed {

  // Fix z-index.
  .toolbar-oriented .toolbar-bar {
    z-index: ($zindex-navbar-fixed + 1);
  }

  .navbar-fixed-top {
    top: 39px;
  }

  // Horizontal.
  &.toolbar-horizontal.toolbar-tray-open .navbar-fixed-top {
    top: 79px;
  }

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nasser_’s picture

I propose this patch that works very well, which allows to scroll to the correct element required that contains the error generated when not filled

nasser_’s picture

I propose this patch that works very well, which allows to scroll to the correct element required that contains the error generated when not filled

Status: Needs review » Needs work

The last submitted patch, 24: toolbar_html5_required_fixed_position-2808699-23.patch, failed testing.

nasser_’s picture

Status: Needs work » Needs review
trevorbradley’s picture

I just hit this after finding #546126: Toolbar interferes with anchor links... It looks like things have come full circle... :)

After a bit of struggle managed to get the CSS in #12 working. (#21 didn't seem to work for me because my subtheme SCSS didn't have access to $zindex-navbar-fixed. Any ideas on how to get around this?)

I do have a word of warning: #12 fails (in Firefox and Chrome) if the targeted div has a border of any kind. In Bootstrap, divs with class "panel" have a 1px solid transparent border.

It's too late on Friday for me to have a theory as to why this might be. I can't see why it would fundamentally alter how the ":before" CSS is functioning.

It might make sense to use a proper name attribute on an orphaned anchor tag, rather than trying to reference the div's by their id attribute.

alexpott’s picture

The patch in #14 works for me in Firefox and Chrome and also with changing the font-size. I think a CSS solution is preferable to a JS solution.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nasser_’s picture

Status: Needs review » Closed (duplicate)

This is a duplicated issue : https://www.drupal.org/node/1870006

sokru’s picture

Version: 8.5.x-dev » 9.3.x-dev
Status: Closed (duplicate) » Needs work

I'm afraid I need to re-open this issue, since #1870006: HTML5 validation with table sticky header is misaligned over the toolbar only partially fixed the issue.
If user with toolbar clicks the anchor link, it is positioned correctly, but if the anchor is reached on full page load (e.g. someone sends the link), then the Toolbar is on top of the anchor.

nod_’s picture

Issue tags: +JavaScript

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

This was a bugsmash target issue today. smustgrave was not able to reproduce the problem and suggested this is outdated. larowlan said we now have the offset library and agreed.

Therefor, I am closing this as outdated.