左对齐 CSS 下拉菜单

发布于 2024-08-14 17:15:27 字数 415 浏览 4 评论 0原文

我有一个网站,它具有通常的 2 级导航,采用下拉菜单的形式,使用 Suckerfish 和

  • 构造来创建菜单。

问题是菜单在页面上右对齐,因此我需要将下拉菜单向左推出,如图所示,以将它们保留在页面内:

下拉菜单 http://pistar.net/share/sample-dropdown.png

如果顶级菜单选项卡的大小相同,则不会一个问题,但它们的宽度是可变的,所以我不能使用预先计算的负边距。

问题是,怎样才能达到这样的效果呢?我宁愿不使用 javascript 来正确对齐它们,但担心这可能是唯一的解决方案。

I have a website with your usual 2 level navigation in the form of a dropdown using Suckerfish and the <ul><li> construct to create the menu.

The problem is the menu is right aligned on the page, thus I'll need to make the dropdowns push out to the left, as shown, to keep them within the page:

Dropdown http://piestar.net/share/sample-dropdown.png

If the top level menu tabs were the same size it wouldn't be a problem, but they are variable width so I cannot use a pre-calculated negative margin.

The question is, how can this effect be achieved? I'd rather not use javascript to align them correctly but fear it may be the only solution.

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

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

发布评论

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

评论(1

墨落成白 2024-08-21 17:15:27

使用 css 属性

right:0;
top:20px; # or whatever height from the top of the parent
position:absolute;

在子菜单 ul 上

position:relative;

,也可能在父菜单 li 上使用。

Use the css property

right:0;
top:20px; # or whatever height from the top of the parent
position:absolute;

on the submenu ul, and possibly

position:relative;

on the parent li.

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