【问题标题】:How to show logo and title in single line?如何在单行中显示徽标和标题?
【发布时间】:2016-01-24 18:47:22
【问题描述】:

我将我的主题从 24 延伸。我现在有这个头文件:

<header id="masthead" class="site-header" role="banner">
    <div class="header-main">
        <img class="site-logo" src="<?php echo bloginfo('stylesheet_directory');?>/images/ic_logo.png" alt="Image" width="32" height="32"/>
        <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>

        <div class="search-toggle">
            <a href="#search-container" class="screen-reader-text" aria-expanded="false" aria-controls="search-container"><?php _e( 'Search', 'twentyfourteen' ); ?></a>
        </div>

        <nav id="primary-navigation" class="site-navigation primary-navigation" role="navigation">
            <button class="menu-toggle"><?php _e( 'Primary Menu', 'twentyfourteen' ); ?></button>
            <a class="screen-reader-text skip-link" href="#content"><?php _e( 'Skip to content', 'twentyfourteen' ); ?></a>
            <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu_id' => 'primary-menu' ) ); ?>
        </nav>
    </div>

    <div id="search-container" class="search-box-wrapper hide">
        <div class="search-box">
            <?php get_search_form(); ?>
        </div>
    </div>
</header>

标志图像的 CSS 类:

.site-logo {
    float: left;
}

基本主题 CSS 样式:

.site-title {
    float: left;
    font-size: 18px;
    font-weight: 700;
    line-height: 48px;
    margin: 0;

    /* Nav-toggle width + search-toggle width - gutter = 86px */
    max-width: -webkit-calc(100% - 86px);
    max-width:         calc(100% - 86px);
}

.site-title a,
.site-title a:hover {
    color: #fff;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

但是标识在网站名称上方显示...

如何将其对齐为单个字符串?

【问题讨论】:

  • 这是logotype?
  • 这个&lt;img class="site-logo" src="&lt;?php echo bloginfo('stylesheet_directory');?&gt;/images/ic_logo.png" alt="Image" width="32" height="32"/&gt;在我的主题文件夹中。
  • 所以你想要h1 和图像/标志一行一行?
  • 是的,我需要在文字(网站名称)之后显示徽标和文字。

标签: php html css wordpress-theming


【解决方案1】:

这里需要了解的 CSS 属性是 display 属性。 img 标签的显示值为inline-block,所以它有宽度和高度,会显示在同一行。但是,h1 标记的显示值为block。块级元素本质上在其前后放置一个换行符,使它们显示在自己的行上。

您可以通过将h1 设置为inlineinline-block 元素来克服此问题:

h1 { display: inline-block; }

或者通过使用float 属性来克服这种行为。对于新手来说,这将有点棘手。 W3Schools provide this article,您可能会觉得很有用。

【讨论】:

  • 我试了一下,但没有任何改变。 .site-title { font-size: 20px; display: inline-block; } .site-logo { float: left; display: inline-block; }
  • 基本主题风格:.site-title { float: left; font-size: 18px; font-weight: 700; line-height: 48px; margin: 0; /* Nav-toggle width + search-toggle width - gutter = 86px */ max-width: -webkit-calc(100% - 86px); max-width: calc(100% - 86px); } .site-title a, .site-title a:hover { color: #fff; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  • 我认为试图解决这个问题会导致你层层叠加冲突的 CSS。如果是我,我会删除与 float 和 width 相关的所有内容并重新开始,只需对 h1 进行简单的 display:inline-block; 声明。
  • 你是对的!我通过 span 更改了 h1 并定义了自定义样式而不覆盖所有工作! :) 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
相关资源
最近更新 更多