选择完整的基于 CSS 的菜单和基于 Javascript/CSS 的菜单的理由是什么?
在考虑为您的网站提供新菜单时,您会验证哪些要点?
- 为什么我应该选择基于 CSS 的完整菜单?
- 为什么我应该选择基于 Javascript/CSS 的菜单?
- 选择其中任何一个有什么好处?
CSS 菜单旧了吗?还是功能有限!我不认为 CSS 菜单已经过时,因为我仍然会选择一千个使用完整 CSS 菜单的 web2.0 网站(没有 JavaScript 来控制其下拉菜单)。
What would be the points you validate when considering a new menu for your website?
- Why should i choose complete CSS based menu ?
- Why should i choose Javascript/CSS based menu ?
- whats is the benefit in choosing either of them?
Is CSS menu old ? or is it limited in features! I dont think CSS menu is old as i still a pick a thousand web2.0 site using complete CSS menu (No javascript to control its dropdowns).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我默认使用纯CSS,除非有一些东西我无法用CSS动画完成,那么我会考虑切换到JS。除非您需要跨多个元素的一些奇特的定时动画或者 CSS 动画无法处理的古怪内容,否则您很少需要 JS。
使用纯 CSS,即使客户端禁用了 JS,菜单仍然可以工作。另外,使用纯 CSS 通常可以减少代码量,这总是好的。
一个很好的看待方式:当您将鼠标悬停在链接上时,您会使用 JS 来更改链接的颜色,还是使用 CSS?这只是一个更复杂但通常相似的问题。
I default to pure CSS unless there is something I can't pull off with CSS animations, then I'll consider switching to JS. It's pretty rare you'll need the JS unless you need some fancy timed animation across multiple elements or something wacky that CSS animations can't handle.
Using pure CSS the menu still works even when the client has JS disabled. Plus with pure CSS it's usually less code, which is always nice.
A nice way to look at it: would you use JS to change the color of a link when you hover over it, or CSS? This is just a more complicated, but usually similar, question.
CSS 控制布局(以及有限的交互,例如
悬停
),而 Javascript 控制逻辑。如果您的菜单中不需要任何逻辑(例如将隐藏的 div 元素显示为子菜单),那么单独使用 CSS 就可以了。
CSS controls the layout (and limited interactions, such as
hover
) while Javascript controls logic.If you don't need any logic in your menu (such as displaying a hidden div element as a submenu), then using CSS on its own is just fine.