正在寻求帮助。我正在帮助将网站从Drupal 7升级到8。 我无法解决的问题之一是,将鼠标悬停在下拉菜单上时如何显示它们。
您可以在以下网站上查看其工作原理: https://eerr.org.uk/
以及它在这里如何不起作用: https://www.drupal8.eerr.org.uk/
我想知道是否有人可以帮助我,我不太擅长CSS和HTML,所以欢迎任何建议。
谢谢 标记
编辑
我真的希望有人能帮助我编辑现有代码,而不仅仅是向我发送指向以独立代码创建下拉菜单的链接。
现有代码似乎是在以下.twig文件中生成的(再次,我对此没有开发经验)
themes / contrib / bootstrap_barrio / templates / navigation / menu--main.html.twig
'''
{#
/**
* @file
* Bootstrap Barrio's override to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
* - is_expanded: TRUE if the link has visible children within the current
* menu tree.
* - is_collapsed: TRUE if the link has children within the current menu tree
* that are not currently visible.
* - in_active_trail: TRUE if the link is in the active trail.
*/
#}
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('nav navbar-nav') }}>
{% else %}
<ul class="dropdown-menu">
{% endif %}
{% for item in items %}
{%
set classes = [
menu_level ? 'dropdown-item' : 'nav-item',
item.is_expanded ? 'menu-item--expanded',
item.is_collapsed ? 'menu-item--collapsed',
item.in_active_trail ? 'active',
item.below ? 'dropdown',
]
%}
<li{{ item.attributes.addClass(classes) }}>
{%
set link_classes = [
not menu_level ? 'nav-link',
item.in_active_trail ? 'active',
item.below ? 'dropdown-toggle',
item.url.getOption('attributes').class ? item.url.getOption('attributes').class | join(' '),
'nav-link-' ~ item.url.toString() | clean_class,
]
%}
{% if item.below %}
{{ link(item.title, item.url, {'class': link_classes, 'data-toggle': 'dropdown', 'aria-expanded': 'false', 'aria-haspopup': 'true' }) }}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{% else %}
{{ link(item.title, item.url, {'class': link_classes}) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
'''
答案 0 :(得分:1)
悬停鼠标可以使用JavaScript。
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover
答案 1 :(得分:0)
Learn how to create a hoverable dropdown menu with CSS.
.dropdown-content {
display: none;
}
.dropdown-content a {
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">This</a>
<a href="#">Shows </a>
<a href="#">On</a>
<a href="#">HOVER</a>
</div>
</div>
这是使其正常工作所需的最少代码。您可以在源代码上看到更多样式。
答案 2 :(得分:0)
请记住,hover
不适合移动设备使用。
这只是一个建议;手机和触摸板上没有hover
事件。因此,如果您的网站可能在这些设备上使用,则应保留click
或实施touch
事件。