gpt4 book ai didi

html - 如何修复 Wordpress 管理栏破坏 100% 高度

转载 作者:太空狗 更新时间:2023-10-29 15:56:32 25 4
gpt4 key购买 nike

我正在使用 Wordpress 创建适合屏幕的网站。

当站点所有者登录时,管理栏会出现,但它添加了以下样式:

html{ margin-top: 28px !important; }

这会导致出现垂直滚动条。有什么方法可以仅使用 CSS 来解决这个问题吗?

Someone had a similar issue但他没有得到答复。

我的相关html结构:

<html>
<body>
<div id="page">
<div class="site-main" id="main">
<div class="content-area" id="primary">

<div role="main" class="site-content" id="content">

</div><!-- #content .site-content -->

</div><!-- #primary .content-area -->
</div><!-- #main .site-main -->
</div><!-- #page -->

<div id="wpadminbar">

</div>

</body>
</html>

和相关的 CSS:

html, body, #page {
width: 100%;
height: 100%;
min-width: 350px;
margin: 0;
padding: 0;
}
#main {
height: 100%;
}
#primary {
float: right;
width: 100%;
margin-left: -200px;
height: 100%;
}
#content {
margin-left: 250px;
height: 100%;
}

对于管理栏:

#wpadminbar {
height: 28px;
left: 0;
min-width: 600px;
position: fixed;
top: 0;
width: 100%;
z-index: 99999;
}

我试过使用(负)边距和填充,还将管理栏的 position 设置为 absolute 而不是 fixed 但没有成功.

最佳答案

查看开头的 wordpress/wp-includes/class-wp-admin-bar.php,您会发现这一点。仔细观察实际答案的评论:

if ( current_theme_supports( 'admin-bar' ) ) {
/**
* To remove the default padding styles
* from WordPress for the Toolbar,
* use the following code:
* add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
*/
$admin_bar_args = get_theme_support( 'admin-bar' );
$header_callback = $admin_bar_args[0]['callback'];
}

if ( empty($header_callback) )
$header_callback = '_admin_bar_bump_cb';

add_action('wp_head', $header_callback);

wordpress/wp-includes/admin-bar.php 包含 _admin_bar_bump_cb 的默认实现:

/**
* Default admin bar callback.
*
* @since 3.1.0
*/
function _admin_bar_bump_cb() { ?>
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
<?php
}

关于html - 如何修复 Wordpress 管理栏破坏 100% 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com