2016-01-24 32 views
1

我把我的主題從二十四個擴展了出來。而我現在這個頭PHP:如何在單行顯示徽標和標題?

<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類logo圖片:

.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; 
} 

但標識顯示上述網站名稱...

如何將其對齊到單個字符串?

+0

這是'logotype'? – RamRaider

+0

這個'

+0

所以你希望'h1'和圖片/標誌一行一行? – RamRaider

回答

2

您需要了解的CSS屬性是display屬性。 img標籤的顯示值爲inline-block,因此它具有寬度和高度,並且將顯示在同一行上。但是,h1標籤的顯示值爲block。塊級元素基本上在它們之前和之後放置一個換行符,使它們顯示在自己的行上。

您可以通過使h1inlineinline-block元素克服這種行爲:

h1 { display: inline-block; } 

或使用float屬性來克服這種行爲。對於新手來說,這將會更加棘手。 W3Schools provide this article,您可能會覺得有用。

+0

我嘗試,但什麼都沒有改變'.site標題。{ \t字體大小:20像素; \t顯示:inline-block的; } .site-標誌{ \t浮動:左; \t顯示:內聯塊; }' –

+0

這是基本主題樣式:'.site-標題{ \t浮動:左; \t font-size:18px; \t font-weight:700; \t line-height:48px; \t margin:0; \t/*導航切換寬度+搜索切換寬度-gutter = 86px */ \t max-width:-webkit-calc(100% - 86px); \t max-width:calc(100% - 86px); } .site-title a, .site-title a:hover { \t color:#fff; \t display:block; \t溢出:隱藏; \t text-overflow:ellipsis; \t white-space:nowrap; }' –

+1

我認爲試圖解決這個問題導致你將層層疊疊的衝突CSS。如果是我,我會刪除所有與浮點數和寬度有關的事情,然後重新開始,只需一個簡單的'display:inline-block;''h1'聲明。 – HenryTK