CSS不是我的强项。我无法实现要使用z-index
进行导航以使其位于前台的目标。我尝试了这种方法,包装器position relative
(也对nav
)和儿童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/