简体   繁体   English

响应式菜单不适用于小屏幕

[英]Responsive menu not working for small screens

I am trying to create a responsive navigation menu. 我正在尝试创建一个响应式导航菜单。 I found some tutorials online and after finding one that I liked the style of, I followed the directions to create it on my website, but I can't seem to get a couple features working. 我在网上找到了一些教程,找到了喜欢的样式后,便按照说明在我的网站上进行了创建,但是似乎无法使用几个功能。

1: I can't get the hover effect to work that adds a bottom border to the icons/links to help accent the one that is in focus. 1:我无法使鼠标悬停效果正常工作,该效果会在图标/链接上添加底边框以帮助突出显示焦点。

2: When getting down to a screen size that is below 32.5em (519px), the menu is supposed to become a single column menu that folds up. 2:当屏幕尺寸降至32.5em(519px)以下时,该菜单应该成为可以折叠的单列菜单。 The menu does become a single column, but it doesn't fold up into a button like it is supposed to. 菜单确实变成了单列,但没有像预期的那样折叠成一个按钮。 It keeps displaying all of the links which takes up a lot of vertical space. 它一直显示所有链接,这些链接占用了大量垂直空间。

Here is a jsFiddle of my project so you can see what I have so far:
https://jsfiddle.net/4Ljs1bfn/1/

You need to use the js detection that the example uses. 您需要使用示例使用的js检测。

  1. Add class="no-js" to your body element. class="no-js"到您的body元素。
  2. Then on load, set document.body.className = "js" (or equivalent). 然后在加载时,设置document.body.className = "js" (或等效名称)。

This will enable the menu. 这将启用菜单。

For the :hover problem, you need the class="no-touch" on your body element (then remove it using js if a touchscreen is detected). 对于:hover问题,您需要在body元素上使用class="no-touch" (然后,如果检测到触摸屏,则使用js将其删除)。

Another thing: You have a html error at <a href="...""> on line ~8 (that extra " at the end). 另一件事: <a href="..."">行的<a href="..."">出现html错误(末尾有多余的“)。

Updated fiddle: https://jsfiddle.net/4Ljs1bfn/2/ . 更新的提琴: https : //jsfiddle.net/4Ljs1bfn/2/ You still have some css issues, but I assume you can fix them yourself. 您仍然有一些CSS问题,但是我想您可以自己解决这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM