根据导航菜单的大小应用不同的图像
我想根据
我正在尝试使用下拉框设计 WordPress 菜单的样式,但我有很多链接名称,这些名称位于一行中,但很少有行更长,并且它们被分成两部分。
对于那些
我想出了这段代码,当然,它不起作用:
var line_height = $("nav li").height();
if(line_height > 34){
$(this).css("background-image", url("images/nav-two-lines.png"))
}
我尝试检查 line_height 值,它是 34px。我打赌它只读取第一个元素,确实,它是一行,高度是 34px。
我希望,有人可以提供帮助。
谢谢!
I want to use different background images according to size of <li> element for navigation menus.
I'm trying to style Wordpress menu, with dropdown boxes, but I have lots of link names, which goes in one line, but few lines are longer, and they are splitting in two.
For those <li> elements, which goes in one line, I applied background image using simple CSS, but I want to check, if there are some <li> elements, which height is more than height for one line. In my case, one line height is 34px; if there are two lines, height is already 54px, and default background image does not suit there (it repeats it self). But I want to apply larger image for that 54px box with jquery.
I came up with this code, which, of course, is not working:
var line_height = $("nav li").height();
if(line_height > 34){
$(this).css("background-image", url("images/nav-two-lines.png"))
}
I tried to check that line_height value, and it was 34px. I bet it reads only first element, and true, its one line, and its height is 34px.
I hope, there would be anyone, who could help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果问题是图像重复,您需要将 CSS 修改为:
在回答您的问题时,您需要循环遍历所有 li,而不仅仅是测试一个:
If the issue is that the image repeats itself, you want to modify the CSS to read:
In answer to your question, you need to loop through all of the li's, not just test one: