0

我正在使用 OpenCart 3,Bootstrap 3。关注以下几行:

<li><a href="#">Sản phẩm</a>
    {% for category in categories %}
        <ul class="list-unstyled dropdown">
            <a href="{{ category.href }}">{{ category.name }}</a>
        </ul>
    {% endfor %}
</li>

文件menu.twig的全部内容:

{% if categories %}
    <div class="container">
        <nav id="menu" class="navbar">
            <div class="navbar-header"><span id="category" class="visible-xs">{{ text_category }}</span>
                <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse"
                        data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
            </div>
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav">
                    <li><a href="#">Trang chủ&lt;/a></li>

                    <li><a href="#">Sản phẩm</a>
                        {% for category in categories %}
                            <ul class="list-unstyled dropdown">
                                <a href="{{ category.href }}">{{ category.name }}</a>
                            </ul>
                        {% endfor %}
                    </li>

                    <li><a href="#">Dịch vụ&lt;/a></li>
                    <li><a href="#">Tư vấn</a></li>
                    <li><a href="#">Công nghệ&lt;/a></li>
                    <li><a href="#">Tin tức</a></li>
                    <li><a href="#">Giới thiệu</a></li>
                    <li><a href="#">Tuyển dụng</a></li>
                    <li><a href="{{ contact }}">Liên hệ&lt;/a></li>

                    {#{% for category in categories %}#}
                        {#{% if category.children %}#}
                            {#<li class="dropdown"><a href="{{ category.href }}" class="dropdown-toggle"#}
                                                    {#data-toggle="dropdown">{{ category.name }}</a>#}
                                {#<div class="dropdown-menu">#}
                                    {#<div class="dropdown-inner"> {% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}#}
                                            {#<ul class="list-unstyled">#}
                                                {#{% for child in children %}#}
                                                    {#<li><a href="{{ child.href }}">{{ child.name }}</a></li>#}
                                                {#{% endfor %}#}
                                            {#</ul>#}
                                        {#{% endfor %}</div>#}
                                    {#<a href="{{ category.href }}" class="see-all">{{ text_all }} {{ category.name }}</a>#}
                                {#</div>#}
                            {#</li>#}
                        {#{% else %}#}
                            {#<li><a href="{{ category.href }}">{{ category.name }}</a></li>#}
                        {#{% endif %}#}
                    {#{% endfor %}#}



                </ul>
            </div>
        </nav>
    </div>
{% endif %}

菜单不能自动折叠,显示不正确。 在此处输入图像描述

如何修复菜单?

4

1 回答 1

1

要修复下拉菜单,请替换:

<li><a href="#">Sản phẩm</a>
  {% for category in categories %}
  <ul class="list-unstyled dropdown">
    <a href="{{ category.href }}">{{ category.name }}</a>
  </ul>
 {% endfor %}
</li>

和:

<li class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#">Sản phẩm
  <span class="caret"></span></a>
  <ul class="dropdown-menu">
  {% for category in categories %}
    <li><a href="{{ category.href }}">{{ category.name }}</a></li>
    {% endfor %}
  </ul>
</li>

它不会崩溃,因为您的崩溃代码看起来不对。您必须将“navbar-header”类 div 替换为:

<div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>

检查文档。向下滚动到底部以“折叠导航栏”。

https://www.w3schools.com/bootstrap/bootstrap_navbar.asp

于 2017-10-19T15:49:15.907 回答