admin管理员组文章数量:1122846
The default approach is to inject it at the end of the html and fix position it at the top.
That approach has worked for years but these days we have something better - position: sticky - and that would keep it on the top and keep elements of the page from sliding underneath it. But for sticky positioning to work it must be the first body element in DOM order.
EDIT: Nevermind. Just make the body "display: flex; flex-flow: column;" and set the order of all children to 1 and the admin-header's order to 0. This will pop it to the top regardless of its DOM position.
The default approach is to inject it at the end of the html and fix position it at the top.
That approach has worked for years but these days we have something better - position: sticky - and that would keep it on the top and keep elements of the page from sliding underneath it. But for sticky positioning to work it must be the first body element in DOM order.
EDIT: Nevermind. Just make the body "display: flex; flex-flow: column;" and set the order of all children to 1 and the admin-header's order to 0. This will pop it to the top regardless of its DOM position.
Share Improve this question edited Aug 23, 2024 at 21:43 Michael Morris asked Aug 21, 2024 at 12:06 Michael MorrisMichael Morris 11 bronze badge 3 |1 Answer
Reset to default 0You don't:
- the admin toolbar isn't trying to be sticky, it's trying to be fixed, they aren't the same thing
- in a modern block theme it already appears before the main site blocks container
- there are already simple solutions for when content slides under it
That approach has worked for years but these days we have something better - position: sticky - and that would keep it on the top and keep elements of the page from sliding underneath it.
Ignoring that the admin toolbar behaves differently on mobile, the problem of sliding underneath already has a solution:
.thing { top: 0; }
.admin-bar .thing { top: 32px; }
Other solutions exist but it's not something that just vanishes by using position: sticky
.
But this all ignores that position: sticky
doesn't match the intended behaviour of the admin toolbar. The admin toolbar is position: fixed
and isn't trying to reproduce the sticky behaviour. Sticky helps when you want something to appear on page then "stick" once the user has scrolled past a certain threshold which isn't what the admin toolbar does.
版权声明:本文标题:Is there a way to get the WP Admin Header to inject as the first element in the body instead of the last? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296966a1929909.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
position: sticky
? Are you trying to make a contribution to WP core? A lot of code has been built based on how that toolbar is positioned that would break with that change – Tom J Nowell ♦ Commented Aug 21, 2024 at 12:27