html - 前台导航——基于引导类和自定义 js

标签 html css bootstrap-4 z-index

css 不是我的强项。我无法实现我想要使用 z-index 进行导航以使其位于前台的目标。我尝试了这种方式,包装器 position relative(也到 nav)和 childrens position absolute

Rowery 有嵌套项。

请帮忙

$(document).ready(function () {
    $('div[data-v]').on('click', function () {
        var that = this;
        var list = $('#main-nav').find('div[data-p=' + $(that).data('v') + ']');

        if (list != 'undefined' || list != null || list.length != 0) {
            list.each(function () {
                var that = this;
                if ($(that).css('display') == "none") {
                    $(that).show(50, function () { $(that).fadeIn("slow"); });
                } else {
                    $(that).hide(50, function () { $(that).fadeOut(); });
                    lookUpForChildrens(that);
                }
            });
        }
    });

    function lookUpForChildrens(that) {
        var list = $('#main-nav').find('div[data-p=' + $(that).data('v') + ']');
        if (list != 'undefined' || list != null || list.length != 0) {
            list.each(function () {
                var that = this;
                if ($(that).css('display') == "block") {
                    $(that).hide(50, function () { $(that).fadeOut(); });
                    lookUpForChildrens(that);
                }
            });
        }
    }
});
.nav-center {
    display: flex;
    justify-content: center;
}

.nav-center-nested {
    position: absolute !important;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 998
}

.kuguar-sport-color {
    background-color: #E31E24;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<body class="bg-danger">

<nav id="main-nav" class="bg-dark">
    <div class="row text-center"><div class="col" data-v="138"><a class="text-black" href="#"> Aktualności</a></div><div class="col" data-v="139"><a class="text-black" href="#"> O nas</a></div><div class="col" data-v="140"><a class="text-black" href="#"> Rowery</a></div></div><div class="position-relative"><div class=".nav-center-nested row text-center"><div style="display: none;" class="col" data-p="140" data-v="368"><a class="text-black" href="#"> Górskie</a></div><div style="display: none;" class="col" data-p="140" data-v="369"><a class="text-black" href="#"> Miejskie</a></div><div style="display: none;" class="col" data-p="140" data-v="370"><a class="text-black" href="#"> Dziecięce</a></div></div></div><div class="position-relative"><div class=".nav-center-nested row text-center"><div style="display: none;" class="col" data-p="368" data-v="371"><a class="text-black" href="#"> testgorskie</a></div><div style="display: none;" class="col" data-p="368" data-v="374"><a class="text-black" href="#"> testgorskie1-1</a></div><div style="display: none;" class="col" data-p="368" data-v="375"><a class="text-black" href="#"> testgorskie1-2</a></div></div></div><div class="position-relative"><div class=".nav-center-nested row text-center"><div style="display: none;" class="col" data-p="371" data-v="372"><a class="text-black" href="#"> testgorskie2</a></div></div></div><div class="position-relative"><div class=".nav-center-nested row text-center"><div style="display: none;" class="col" data-p="372" data-v="373"><a class="text-black" href="#"> testgorskie3</a></div></div></div>
</nav>
<p>What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).


Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
</body>

最佳答案

你只是把类写错了:class=".nav-center-nested"多了一个点,应该是class="nav-center-nested"

这是正确的 HTML 代码:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<body class="bg-danger">

<nav id="main-nav" class="bg-dark">
    <div class="row text-center"><div class="col" data-v="138"><a class="text-black" href="#"> Aktualności</a></div><div class="col" data-v="139"><a class="text-black" href="#"> O nas</a></div><div class="col" data-v="140"><a class="text-black" href="#"> Rowery</a></div></div><div class="position-relative"><div class="nav-center-nested row text-center"><div style="display: none;" class="col" data-p="140" data-v="368"><a class="text-black" href="#"> Górskie</a></div><div style="display: none;" class="col" data-p="140" data-v="369"><a class="text-black" href="#"> Miejskie</a></div><div style="display: none;" class="col" data-p="140" data-v="370"><a class="text-black" href="#"> Dziecięce</a></div></div></div><div class="position-relative"><div class="nav-center-nested row text-center"><div style="display: none;" class="col" data-p="368" data-v="371"><a class="text-black" href="#"> testgorskie</a></div><div style="display: none;" class="col" data-p="368" data-v="374"><a class="text-black" href="#"> testgorskie1-1</a></div><div style="display: none;" class="col" data-p="368" data-v="375"><a class="text-black" href="#"> testgorskie1-2</a></div></div></div><div class="position-relative"><div class="nav-center-nested row text-center"><div style="display: none;" class="col" data-p="371" data-v="372"><a class="text-black" href="#"> testgorskie2</a></div></div></div><div class="position-relative"><div class="nav-center-nested row text-center"><div style="display: none;" class="col" data-p="372" data-v="373"><a class="text-black" href="#"> testgorskie3</a></div></div></div>
</nav>
<p>What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).


Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
</body>

关于html - 前台导航——基于引导类和自定义 js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55221885/

相关文章:

javascript - 下拉 Div 在悬停时保持可见 jQuery

css - bootstrap 在某些断点处改变 flex 方向?

JavaScript - 使用 AppendChild() 将新行添加到表中

css - Bootstrap 导航栏教程不适用于任何浏览器

html - 样式输入元素以填充其容器的剩余宽度

javascript - Contenteditable,删除删除 charat caret + Chrome 中使用::before 生成的内容

css - Div 垂直中间的文本

css - 在 AngularJS 中禁用输入类型 =“number” 上的 webkit 旋转按钮

css - 用变量编写 SASS 循环

css - float 跨度增加了IE中div的宽度