如何创建顶部链接宽度可变的右对齐 suckerfish 菜单?

发布于 2024-11-15 04:36:08 字数 1218 浏览 4 评论 0原文

我创建了一个 Son of Suckerfish (http://htmldog.com/articles/suckerfish/dropdowns/) 基于 CSS 的导航菜单。左侧是普通的 Suckerfish,其中顶级导航条目与下拉菜单的宽度相同。

在菜单的右侧,有几个小图标,用于显示帮助和带有下拉菜单的选项等内容。问题是我需要将它们右对齐,这样它们就不会脱离页面,因为图标很窄并且向右浮动。

文字图片时间:)

_______________________________________________________
| menu-item    | menu-item    |       ____________| ? |
--------------------------------------| help item 1   |
                                      | help item 2   |
                                      | etc           |
                                      -----------------

我做的有点成功的是将负左边距应用于保存下拉条目的内部:

#nav li ul { width: 10em; margin-left: -10em; }

有一个问题,它最终太靠左了:

_______________________________________________________
| menu-item    | menu-item    |  _________________| ? |
---------------------------------| help item 1   |-----
                                 | help item 2   |
                                 | etc           |
                                 -----------------

一个简单的解决方案是将我的宽度基于 px 而不是em 并将负左边距减少我的图标的宽度(16px),但这很hacky。它不会处理字体缩放。我想到的另一个技巧是使用 margin-left:-9em;并使我的图标元素宽度:1em;但这似乎也有点奇怪。我希望有人有更好的主意!

I have created a Son of Suckerfish (http://htmldog.com/articles/suckerfish/dropdowns/) CSS-based nav menu. The left side is normal Suckerfish where the top-level nav entry is the same width of the drop-downs.

On the right side of my menu I have several small icons for things like help and options that also have drop-down menus. The problem is I need to right-align them so they do not go off the page, because the icons are narrow and floated right.

Word picture time :)

_______________________________________________________
| menu-item    | menu-item    |       ____________| ? |
--------------------------------------| help item 1   |
                                      | help item 2   |
                                      | etc           |
                                      -----------------

What I did somewhat successfully was apply negative left margin to the inner that holds the drop-down entries:

#nav li ul { width: 10em; margin-left: -10em; }

There's one problem, it ends up too far left:

_______________________________________________________
| menu-item    | menu-item    |  _________________| ? |
---------------------------------| help item 1   |-----
                                 | help item 2   |
                                 | etc           |
                                 -----------------

A simple solution would be to base my widths on px instead of em and reduce the negative left-margin by the width of my icon (16px), but that is hacky. It won't handle font zooming. Another trick I thought up would be to use margin-left:-9em; and make my icon element width:1em; but that seems a little wonky too. I'm hoping someone has a better idea!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-11-22 04:36:08

好吧,我为此整理了一个小提琴并找到了解决方案...请参阅我的小提琴 http://jsfiddle.net /cssguru/7JMkp/。没有时间在所有浏览器中进行验证。可能需要对 IE 进行一些调整。

Ok, I put together a fiddle for this and found a solution... See my fiddle http://jsfiddle.net/cssguru/7JMkp/. Didn't have time to verify in all browsers. Probably some IE tweaking needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文