基于触摸的客户端上的 CSS 下拉菜单。纯 CSS 下拉菜单会消失吗?

发布于 2024-08-31 19:17:25 字数 242 浏览 3 评论 0原文

我的公司正开始将 iPad 添加为浏览器,我必须在其上测试我的工作。这让我开始思考...

既然基于触摸的客户端没有 :hover 状态,纯 CSS 下拉菜单会消失吗?

然后我想即使你添加一些 JavaScript 来使菜单在单击时弹出......当菜单项(扩展到另一个菜单)也是一个链接时会发生什么。您如何区分单击查看菜单和单击转到该链接之间的区别?

当基于触摸的客户端变得更加普遍时,下拉菜单会发生什么?还有解决方法吗?

My company is starting to move toward adding the iPad as a browser i have to test my work on. This got me thinking...

Since touch-based clients don't have a :hover state are pure CSS dropdowns going to go away?

Then i thought even if you add some javascript to make the menus popup on click... What happens when the menu item (that expands to another menu) is also a link. How do you tell the difference between a click to see the menu or a click to go to that link?

What's going to happen with dropdown menus when touch based clients become more ubiquitous? Are there any workarounds out there yet?

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

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

发布评论

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

评论(3

好听的两个字的网名 2024-09-07 19:17:25

由于 :target 伪类,纯 CSS 下拉菜单可以在触摸设备上实现。基本上,伪类对于具有与当前 URL 片段匹配的 id 的对象是活动的。这意味着 URI 片段可用于存储状态并与 CSS 共享状态。例如,假设我们在 http://example.com/ 上,它具有以下 HTML 和 CSS:

<style>
    #menu {
        display: none;
    }
    #menu:target {
        display: block;
    }
</style>

<a href="#menu">Show the Menu!</a>
<div id="menu"> ... </div>

菜单默认是隐藏的。单击或点击链接会将 URL 片段更改为“菜单”(完整 URI:http://example.com/#menu )。因为现在有一个 id 等于 URI 片段(“菜单”)的元素,所以 :target 伪类适用,并且显示属性发生更改。

进一步阅读:

Pure CSS dropdowns are possible on touch devices thanks to the :target pseudo-class. Basically, the pseudo-class is active for objects that have an id matching the current URL fragment. This means that the URI fragment can be used to store and share state with CSS. For example, let's say we're on http://example.com/, which has the following HTML and CSS:

<style>
    #menu {
        display: none;
    }
    #menu:target {
        display: block;
    }
</style>

<a href="#menu">Show the Menu!</a>
<div id="menu"> ... </div>

The menu is hidden by default. Clicking or tapping the link will change the URL fragment to "menu" (full URI: http://example.com/#menu). Because now there is an element with an id equal to the URI fragment ("menu"), the :target pseudo-class applies, and the display property is changed.

Further reading:

扮仙女 2024-09-07 19:17:25

这是一种由技术问题造成的设计问题。我可能会通过以下三种方式之一重新设计/重新组织我的内容:

1- 单击激活的大型菜单(示例)。这里的缺点是你可能会遇到房地产问题。

2- 通往导航页面的顶级类别链接。这里的缺点是它需要额外的页面加载才能获取内容。

3-使每个菜单项包含两个按钮,一个用于导航到页面(文本),一个用于展开子菜单(箭头)。不过,您仍然需要提供子导航(如果存在),用户单击菜单项时进入的页面。

This is kind of a design issue forced by a technical issue. I'd probably redesign/reorganize my content into one of three ways:

1- Click-activated mega-menus (example). The downfall here is that you might have real estate issues.

2- Top-Level Category links that lead to Navigation Pages. The downfall here is that it requires an extra page load to get to the content.

3- Make each Menu Item consist of two buttons, one to navigate to the page (the text) and one to expand the child menu (an arrow.) You'd still need, though, to provide the child navigation, if present, on the page the user goes to when they click a menu item.

¢好甜 2024-09-07 19:17:25

我的导航栏有这个功能(collins.class401.com/nav),可以满足您的需要
它是 TJK_DropDownMenu http://www.tjkdesign.com/articles/keyboard_Friendly_dropdown_menu/ 的修改版本默认.asp
他们的版本(和我的)使用 :hover 的可见性
他们的版本也只支持将 作为菜单项,而我的版本也支持 (尽管使用 span 会破坏他们的键盘导航),如果您想要诸如表单或菜单中的按钮之类的东西,例如我有
他们的版本通常适用于 :hover on iPod touch,只要您单击“空白”
我的版本对触摸设备更加友好,并且具有可点击的箭头来使用prototype.js切换显示,

或者,如果它们无法悬停,并且javascript关闭,则设置一个php会话并重新加载页面,然后插入style 为页面末尾的样式标签,该标签会覆盖可见性,并根据点击显示或隐藏来显示

my nav bar has this functionality (collins.class401.com/nav) for the crap you need
its a modified version of TJK_DropDownMenu http://www.tjkdesign.com/articles/keyboard_friendly_dropdown_menu/default.asp
their version (and mine) uses visibility for :hover
their version also only supports having <a>'s as menu items, while mine also supports <span>s (though using spans breaks their keyboard navigation) if you want something like a form, or a button in your menu, like i have
their version usually works for :hover on ipod touch, as long as you click in the 'white space'
my version is much more friendly to touch devices, and has the clickable arrows to toggle the display using prototype.js,

or, if they can't hover, and javascript is off, setting a php session and reloading the page, then inserting a style to the style tag at the end of the page which will overwrite the visibility and display according to whether the clicked to show or hide

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