douzhongju8780 2015-02-25 22:08
浏览 32

Wordpress导航css

I'm migrating my HTML / CSS website to WordPress (creating a theme). I'm using the code shown below to turn wordpress 'pages' into navigation li links.

The code works, But the Word press nav styling is slightly different to the HTML site.

The code should work the same in both cases, but I suspect WP is not applying either an id or class

Can anyone help me understand why these code snippets give different styling results (The same css sheet is used for both the wordpress and the non wordpress site)

WP nav code (found in header.php)

    <nav>
      <ul id="navigation" class="slimmenu"> 
        <?php wp_nav_menu(); ?>  
      </ul>
    </nav>  

HTML site nav code

<nav>
  <ul id="navigation" class="slimmenu"> 
    <li><a href="bike-shed.php">Home</a></li>
    <li><a href="mountain-bikes.php">Bikes</a></li>
    <li><a href="bicycle-parts.php">Parts</a></li>
    <li><a href="charity-bikeevents.php">Events</a></li>
    <li><a href="contact-bikeshed.php">Contacts</a></li>
  </ul>
</nav>

many thanks,

  • 写回答

1条回答 默认 最新

  • dsft8327 2015-02-25 22:15
    关注

    You should not have wp_nav_menu() inside a <ul> element.

    This function creates HTML which includes a wrapper (div) and it's own <ul> element. so your HTML is going to be invalid and your CSS is unlikely to work.

    Just use:

    <nav>
        <?php wp_nav_menu( array( 'menu_id' => 'navigation', 'menu_class' => 'slimmenu') ); ?>  
    </nav>  
    

    If your CSS selectors are not overly specific, they may still work with the HTML generated by WordPress.

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了