Chrome 中的子菜单定位错误
这就是我想要的(以及在 Firefox 和 IE 中有效的)。箭头图像正确定位在菜单项的右侧:
但这是Chrome 中的样子:
<div id="main-nav">
<ul class="tabbed">
<li><a href="#">Link 1 (submenu)</a><span></span></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</div>
<div class="clearer"> </div>
<div id="sub-nav" style="display:none;">
<ul class="tabbed">
<li><a href="#">Sublink 1</a></li>
<li><a href="#">Sublink 2</a></li>
<li><a href="#">Sublink 3</a></li>
<li><a href="#">Sublink 4 </a></li>
</ul>
<div class="clearer"> </div>
</div>
CSS
ul.tabbed li {
list-style: none;
margin-top: 0;
}
ul.tabbed {
display: inline;
margin: 0;
}
ul.tabbed li {
float: left;
}
ul.tabbed li span { /*--Drop down trigger styles--*/
width: 17px;
height: 35px;
float: right;
background: url("button.gif") no-repeat;
}
ul.tabbed li span.subhover {
background: url("button-hover.gif") no-repeat;
cursor: pointer;
} /*--Hover effect for trigger--*/
您可以看到 此处演示。
我注意到在 Chrome 中添加一个空的 img 标签可以解决问题,但我认为这不是正确的解决方案。
<div id="main-nav">
<ul class="tabbed">
<li><a href="#">Link 1 (submenu)</a><span></span> <img src="" /> </li>
This is what I want (and what works in Firefox and IE). The arrow image is positioned correctly on the right side of the menu item:
But this is what it looks like in Chrome:
<div id="main-nav">
<ul class="tabbed">
<li><a href="#">Link 1 (submenu)</a><span></span></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</div>
<div class="clearer"> </div>
<div id="sub-nav" style="display:none;">
<ul class="tabbed">
<li><a href="#">Sublink 1</a></li>
<li><a href="#">Sublink 2</a></li>
<li><a href="#">Sublink 3</a></li>
<li><a href="#">Sublink 4 </a></li>
</ul>
<div class="clearer"> </div>
</div>
CSS
ul.tabbed li {
list-style: none;
margin-top: 0;
}
ul.tabbed {
display: inline;
margin: 0;
}
ul.tabbed li {
float: left;
}
ul.tabbed li span { /*--Drop down trigger styles--*/
width: 17px;
height: 35px;
float: right;
background: url("button.gif") no-repeat;
}
ul.tabbed li span.subhover {
background: url("button-hover.gif") no-repeat;
cursor: pointer;
} /*--Hover effect for trigger--*/
You can see the demo here.
I noticed that adding an empty img tag does the trick in Chrome, but I don't think is the proper solution.
<div id="main-nav">
<ul class="tabbed">
<li><a href="#">Link 1 (submenu)</a><span></span> <img src="" /> </li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下操作:
移至
内。
ul.tabbed li span
中删除float
。display:inline-block
添加到ul.tabbed li span
并将height
降至 27px。http://jsfiddle.net/ambigously/ekZEw/
你可能需要稍微摆弄一下 CSS多一点以获得您想要的精确视觉外观。
我认为将跨度移动到您想要将其附加到的元素(锚点)内将产生比其他任何东西更可靠的结果。
You could try this:
<span></span>
inside the<a>
.float
fromul.tabbed li span
.display:inline-block
toul.tabbed li span
and drop theheight
to 27px.http://jsfiddle.net/ambiguous/ekZEw/
You might have to fiddle with the CSS a little bit more to get the precise visual appearance that you want.
I think moving the span inside the element you want it attached to (the anchor) will yield more reliable results than anything else.
我稍微调整了你的代码,它可以工作(在 Chrome 中): http://jsfiddle.net/u9NZn/3 /。
以下是我所做的一些更改:
演示: http://fiddle.jshell.net/u9NZn/3 /显示/
I tweaked your code a little, and it works (in Chrome): http://jsfiddle.net/u9NZn/3/.
Here's a few changes I made:
Demo: http://fiddle.jshell.net/u9NZn/3/show/