将自定义标题放在自己的行中

时间:2017-05-30 09:51:35

标签: php html css wordpress custom-headers

我的网站是www.rosstheexplorer.com

根据浏览器的宽度,页面上的插件,H1和其他元素可能与自定义标题重叠。我怎么能防止这种情况发生?我希望页面上的所有其他元素始终低于客户标题。

我的自定义标头的代码是

 @media screen and (min-width: 601px) {
 .custom-header { background: url("https://i1.wp.com/www.rosstheexplorer.com/wp-content/uploads/2017/02/Cover-Photo-6-2.jpg") no-repeat; 
        width: 100% ;
            height: 40%;
        background-size: 100%;

position: absolute;
top: 0px;
left: 0px;

    display: block


}
}

我的header.php的代码(在我修改之前,我在下面解释)是

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="content">
 *
 * @package Penscratch
 */
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( 'A|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
    <a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'penscratch' ); ?></a>
    <img class="custom-header" src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
<header id="masthead" class="site-header" role="banner">
        <div class="site-branding">
            <?php if ( function_exists( 'jetpack_the_site_logo' ) ) jetpack_the_site_logo(); ?>
            <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
            <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
        </div>

        <nav id="site-navigation" class="main-navigation" role="navigation">
            <button class="menu-toggle"><?php _e( 'Menu', 'penscratch' ); ?></button>
            <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
        </nav><!-- #site-navigation -->
    </header><!-- #masthead -->

    <div id="content" class="site-content">
        <?php if ( get_header_image() ) : ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">

            </a>
        <?php endif;  // End header image check. ?>

要将自定义标头放在自己的行中,我尝试使用以下代码

<div class="row">

    <div class="col-sm-12" style="background-color:lavender;"><img class="custom-header" src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt=""></div>

  </div>

这似乎没有效果。

我是否正确安装了Bootstrap?

我尝试使用以下代码。我将代码添加到functions.php文件中。 我使用了https://www.zenwebthemes.com/blog/how-to-add-bootstrap-to-your-wordpress-theme/中的说明。

wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap-3.3.7.css' );


wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js' );

我根据Pratys的建议添加了我的评论的下一部分。我正在使用https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_table_basic&stacked=h上的模拟工具。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Basic Table</h2>
  <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
  <table class="table">

    <tbody>
      <tr>
        <td><img class="custom-header" src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt=""></td>

      </tr>
      <tr>
        <td>Mary</td>

      </tr>

    </tbody>
  </table>
</div>

</body>
</html>

当前是“​​Mary”文本的地方,您是否会将与菜单栏相关的代码放入?

2 个答案:

答案 0 :(得分:0)

我访问了您的网站,当我调整浏览器大小时,它与标题和菜单重叠。

我建议您将自定义标题图像和标头标题放在网格控件的2个不同行中。这样,您可以限制行重叠。

或者,你可以尝试在你的网站上实现bootstrap,你将不会处理浏览器的大小调整,因为它会照顾好自己。

答案 1 :(得分:0)

您是否曾尝试在CSS中将clear:both;添加到CSS中?
https://www.w3schools.com/cssref/pr_class_clear.asp

相关问题