gpt4 book ai didi

jquery - Bootstrap 3 折叠导航栏在展开时不可见,但在悬停时可见

转载 作者:行者123 更新时间:2023-11-28 04:12:55 29 4
gpt4 key购买 nike

自学新手在这里使用最新的 Bootstrap 3。我有一个令我困惑的问题。提前感谢您的宝贵时间。

正如标题所暗示的那样,导航栏在移动设备/较小的屏幕尺寸上完美折叠,按钮看起来符合预期,而且我能够展开它。但是点击后,下拉菜单会突然出现然后消失。当我将鼠标悬停在它们闪过的区域时,导航菜单链接(及其下拉菜单)可见且可点击。该问题在多个浏览器中仍然存在。

我在类似主题中尝试了一些建议的导航栏折叠解决方案,但无济于事(例如更新 jQuery/bootstrap .js 文件,仔细检查数据目标属性,仔细检查链接的 java 脚本,等)。

不确定我在这里犯了什么错误。我很感激任何反馈,因为我正在努力学习。提前致谢!

/*NavBar Gray on Blue*/

.navbar {
margin-bottom: 0;
}

.navbar-inverse {
background: #004a99;
border: 0;
}

.dropdown-menu {
background: #004a99;
border-radius: 0;
border: 0;
}

.navbar-inverse .navbar-brand {
color: #f2f2f2;
}

.navbar-inverse .navbar-brand:hover {
color: #004a99;
}

.navbar-inverse .navbar-nav li a {
color: #f2f2f2;
font-size: 16px;
}

.navbar-inverse .navbar-nav li a:hover {
background: #004a99;
}

.navbar-inverse .navbar-nav .dropdown-menu li a:hover {
background: #f2f2f2;
color: #004a99;
}

.navbar .nav>li.dropdown.open.active>a:hover,
.navbar .nav>li.dropdown.open>a {
color: #004a99;
background-color: #f2f2f2;
border-color: #fff;
}

.dropdown-menu li a {
padding: 10px;
}

.navbar-brand {
padding: 0px;
}

.navbar-brand>img {
height: 100%;
padding: 0px;
width: auto;
}

.navbar-nav.navbar-center {
position: absolute;
left: 50%;
transform: translatex(-50%);
}
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>title</title>
<!--Java and Links-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Merriweather|Raleway:400,500,600,800" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="/img/favicon.ico" />


<body>
<!--NavBar-->
<nav class="navbar navbar-inverse navbar-static-top sans-serif">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!--NavBar Logo<a class="navbar-brand" href="#"><img src="/img/navlogo.png" alt="Logo"></a>//-->
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-center">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">text.<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">text</a></li>
<!--<li><a href="#">text</a></li>//-->
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">text<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">text</a></li>
<li><a href="#">text</a></li>
</ul>
</li>
<li><a href="#">text</a></li>
</ul>
</div>
</div>
</nav>
</body>

最佳答案

问题是 .navbar-center 转换。您可以通过仅在较大宽度上应用居中来修复它:

@media (min-width: 768px) {
.navbar-nav.navbar-center{
position: absolute;
left: 50%;
transform: translatex(-50%);
}
}

Codeply Demo

关于jquery - Bootstrap 3 折叠导航栏在展开时不可见,但在悬停时可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42631225/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com