duanruanxian5028 2013-08-05 19:41
浏览 45
已采纳

在自定义菜单wordpress中添加样式图像

I am a beginner to wordpress and creating my first theme. I am stuck at one place. In my static html, i used images in lists to style my navigation. I am able to make dynamic navigation in wordpress but i am unable to work out for putting my images in li dynamically.

My static code for navigation is here

    <ul>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">Home</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">About</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">Archives</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">Write for Us</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">Sitemap</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
      <li class="li_txt"><a href="#">Contact</a></li>
      <li class="li_img"><img src="imgs/line-img.png" /></li>
    </ul>

How can i get the alternative of this dynamically

   <li class="li_img"><img src="imgs/line-img.png" /></li>
  • 写回答

1条回答 默认 最新

  • dongmi1872 2013-08-05 19:48
    关注

    If you can, I would avoid styling menu items this way. Having a separate li for a border/separator image defeats the purpose of the HTML/CSS relationship. Could you apply the line-img.png to the background of the li element?

    Are you using wp_nav_menu() for the menu? It should generate code similar to:

    <ul class="menu">
        <li id="menu-item-1" class="menu-item">Menu Item</li>
    </ul>
    

    You could could style the above with something like:

    .menu-item {
        background: url(imgs/line-img.png) no-repeat right center;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀