html - 菜单里一个:active how can I make it working properly?

标签 html css

我正在做一个导航栏,我希望当用户按下“showreel”时,其他两个部分出现。我如何使用 CSS 做到这一点?

这是我的代码:

<li><a href="showreel.html">showreel</a>
    <ul>
     <li><a href="showreel.html">director</a></li>
    <li><a href="showreel.html">cinematographer</a></li>
    </ul>

最佳答案

正如其他人提到的,您可能希望使用 :hover 作为悬停菜单。请注意,仅使用键盘无法访问典型的悬停菜单,并且需要付出额外的努力才能使它们在键盘上工作。您需要 Hook 焦点事件才能执行此操作:

Demo

CSS

ul li:hover ul,

ul li.forceShow ul
{
    display:block;
}

ul ul {
    display:none;
}

JS

$('ul a').focusin(function () {
    $(this).parent().toggleClass('forceShow');
});

关于html - 菜单里一个:active how can I make it working properly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19119250/

相关文章:

html - 允许在 HTML 5 可拖动子元素上选择文本

javascript - 将js对象转为html

html - 如何使 float :left work in google chrome on linux

c# - 带有 HTML5 控件的 Visual Studios Formview

html - 使用视口(viewport)将站点保持在固定大小?

html - 图片向右浮动时如何让文字重叠

html - 在 div 元素后添加换行符

jquery - 如何在移动设备(Android、iphone)上使用 Jquery 网络摄像头?

javascript - Javascript 每 2 秒随机化一次图像

javascript - margin right 在 canvas html5 上不起作用,滚动条删除有问题