没有 JavaScript 的 CSS 菜单
任何人都可以提供参考,或者是否可以完全依赖于创建一个菜单 CSS
和 没有一点 javascript
?
要求是一个下拉菜单,可以有许多子菜单(子菜单)
。
像这样创建的任何东西都会跨浏览器兼容
吗?
任何有关此主题的帮助将不胜感激!
编辑
感谢您的所有输入,还有一个疑问
是否可以实现这一点,而不是使用ul li
说div span
组合,因为这可以帮助我实现菜单不会改变我当前的 html 结构!
Can anybody give a reference or is it possible to create a menu entirely depending onCSS
and not a single bit of javascript
?
The Requirement is a dropdown menu, which can have many children ( submenu )
.
Will anything if created like this will be cross browser compatible
?
Any help on this topic will be appreciated!.
EDIT
Thanks for all your inputs one more doubt
Can this be implemented rather than using ul li
say div span
combination as that may help me achieving a menu which won't change my current html structure!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
诀窍是
:hover
伪类。好的?因此,您的整个子菜单必须位于其对应的主菜单项的
内。然后是 CSS:
做一些样式设置,工作就完成了。
编辑:对于另一层菜单,非常简单。使用此 CSS:
请注意,我已将
.menu>li:hover
替换为.menu li:hover
。这告诉浏览器查找主菜单下方的所有li
元素(而不仅仅是直接后代),并在悬停时显示其子菜单。我还放弃了使用子菜单类,因为如果您将 CSS 基于后代,则实际上并不需要它。这将允许您添加任意数量的级别。The trick is the
:hover
pseudo-class.Ok? So your entire submenu has to go inside the
<li>
of the main menu item it corresponds to. Then for the CSS:Do a bit of styling, and job done.
Edit: For another layer of menus, it's really simple. Use this CSS:
Note that I've replaced
.menu>li:hover
with.menu li:hover
. That tells the browser to find allli
elements below the main menu (not just immediate descendants) and show their submenu when hovering. I've also got rid of using the submenu class because it's not really needed if you're basing the CSS on descendants. This will let you add as many levels as you want.检查此网站:http://www.cssplay.co.uk/menus/ 其中有许多不同的菜单,仅 CSS。一个参考。
Check this site : http://www.cssplay.co.uk/menus/ which have a lot of different menus with CSS only. A reference.
看看这个: http://www.cssplay.co.uk/menus/final_drop.html
Check this out: http://www.cssplay.co.uk/menus/final_drop.html
看看这是否有帮助 http://www.howtocreate.co.uk/tutorials/testMenu.html
http://www.texaswebdevelopers.com/blog/template_permalink.asp ?id=129
See if this helps http://www.howtocreate.co.uk/tutorials/testMenu.html
http://www.texaswebdevelopers.com/blog/template_permalink.asp?id=129
当然可以仅使用 CSS 来制作下拉菜单,并且许多网站现在都在使用它。
CSS 还无法提供任何动画卷出等功能 - 菜单只会在可见和隐藏之间切换。如果您想要动画滚动,jQuery 可能是更好的选择。也就是说,CSS 动画确实存在。它仅在一两个浏览器中实现,但您无论如何都可以将其添加到样式表中;它不会破坏不支持它的浏览器;他们只是看不到动画。
CSS菜单的跨浏览器兼容性相对容易,只要忽略IE6即可。 IE7/8 可以毫不费力地工作,但 IE6 对于几乎所有纯 CSS 菜单技术来说都严重损坏。如果可能的话,尽量避免支持 IE6。它是一个旧的浏览器,确实需要让它安静地死去。
其他人已经提供了一些很好的例子的链接,所以我不会在这里重复。
It is certainly possible to do drop-down menus in CSS only, and many sites are now using it.
What you won't get (yet) with CSS are any animated roll-outs, etc - the menu will just toggle between visible and hidden. If you want animated roll-outs, jQuery may be a better option. That said, CSS animation does exist. It is only implemented in one or two browsers, but you could add it to your stylesheet anyway; it won't break browsers that don't support it; they just won't get the animation.
Cross-browser compatibility for CSS menus is relatively easy, as long as you ignore IE6. IE7/8 can be made to work without too much fuss, but IE6 is badly broken for virtually all CSS-only menu techniques. If at all possible, try to avoid having to support IE6. Its an old browser, and really needs to be left to die in peace.
Others have already provided links to some good examples, so I won't repeat them here.
我刚刚完成了针对移动设备的 CSS 菜单的开发,完全使用了零 JavaScript。基本上,通过将
tabindex="-1"
属性应用于您想要的任何内容,您可以允许该元素对:focus
CSS 属性做出反应,而无需实际成为选项卡的一部分顺序(因此您无法通过 Tab 键访问该元素)。将其应用于当前接受的解决方案:我删除了
标签(因为现在我们的下拉菜单是可点击的,我们在我们想要点击的任何内容上插入
tabindex
打开,CSS 更改为:查看我的手机的 Codepen菜单:
I have just finished developing a CSS Menu for mobile devices, using absolutely ZERO Javascript. Basically, by applying the
tabindex="-1"
attribute to anything you want, you allow that element to react to the:focus
CSS property without actually being part of the tab order (so you can't reach that element by tabbing through). Applying this to the currently accepted solution:I removed the
<a>
tags (because now our drop-menus are CLICKABLE, we insert thetabindex
on whatever we want to click on and the CSS gets changed to this:Check out this Codepen for my Mobile Menu: