使用
我有一个垂直的 ul 作为导航菜单。当 a:hover 被触发时,屏幕边缘会出现左边框,并且会调整填充,以便文本不会移位。很常见的菜单效果。效果很好,除非用户将屏幕大小调整到导航菜单项分成两行的程度 - 然后第二行上没有填充,将其拉到左侧。我需要找到一种方法,即使线断了,也能将填充均匀地应用于整个 li,同时保持左边框效果!
我在 stackoverflow 上查看了类似问题的一些答案,但它们似乎都涉及从 li 中删除填充并将其应用于 ul 或包含元素。如果我这样做,那么我会失去左边框突出显示的位置 - 边框显示在文本旁边,并且我无法弄清楚如何操作与 li 分开的边框上的填充以将其重新弹出!
这是 css:
#middle_left ul {
list-style: none;
padding-top:5%;
font-family: 'Gill Sans', Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size:1.5em;
}
#middle_left ul a {
padding-left:15px;
text-decoration: none;
color: #2e2f2a;
}
#middle_left ul a:hover {
padding-left:12px;
color: #81827f;
border-left: solid 3px #81827f;
}
和 HTML:
<div id="middle_left">
<ul>
<li><a href="#">The Novel</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Translation</a></li>
<li><a href="#">Other Works</a></li>
</ul>
</div>
感谢您提供有关如何解决此问题的任何建议!
I have a vertical ul as a nav menu. When a:hover is triggered, a border-left shows up at the edge of the screen and padding is adjusted so the text isn't displaced. Pretty common menu effect. Works well, except when user resizes their screen to the point where the nav menu items break into two lines- then there is no padding on the second line, pulling it to the left. I need to find a way to apply the padding equally to the whole li even if the line is broken, while keeping my border-left effect!
I have looked at some answers to similar problems on stackoverflow but they all seem to involve removing the padding from the li and applying it to the ul or containing element instead. If I do this, then I lose the positioning on my left border highlight- the border shows up right next to the text, and I can't figure out how to manipulate the padding on the border separate from the li to bump it back out!
Here's the css:
#middle_left ul {
list-style: none;
padding-top:5%;
font-family: 'Gill Sans', Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size:1.5em;
}
#middle_left ul a {
padding-left:15px;
text-decoration: none;
color: #2e2f2a;
}
#middle_left ul a:hover {
padding-left:12px;
color: #81827f;
border-left: solid 3px #81827f;
}
And the HTML:
<div id="middle_left">
<ul>
<li><a href="#">The Novel</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Translation</a></li>
<li><a href="#">Other Works</a></li>
</ul>
</div>
Thanks for any suggestions for how to tackle this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 a 包裹在 div 中:
参见此处的示例:
http://jsfiddle.net/6nz9F/2/
Wrap the a in divs:
See here for example:
http://jsfiddle.net/6nz9F/2/
这个怎么样?
CSS
How about this?
CSS