gpt4 book ai didi

html - bootstrap - 为什么我的导航栏没有出现在下一行?

转载 作者:行者123 更新时间:2023-11-28 01:15:55 24 4
gpt4 key购买 nike

我正在尝试创建一个响应式网站:调整窗口大小时,您会看到“移动” View 。于是出现了一个按钮。通过按下按钮,您可以切换导航栏(使其出现和消失)。本网站做this很好:https://blackrockdigital.github.io/startbootstrap-freelancer/

所以我尝试自己复制这个行为:

<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/test.css">

</head>
<body>

<!--Navigation bar-->
<nav class="navbar navbar-custom navbar-fixed-top" id="myNavbar">
<div class="container">
<div class="navbar-brand">
<img src="images/testLogo.png">
</div>
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarResponsive" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right" id="ul">
<li class="active"><a href="main.html">Home</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="projects.html">Partners</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</div>
</nav>
</body>
</html>

CSS:

/**
* Navigation bar.
*/

#myNavbar
{
padding-top: 1.5rem;
padding-bottom: 2.5rem;
background-color: rgb(100, 100, 100);
}

#navbarResponsive
{
width: 65%;
}

.navbar-collapse
{
flex-basis: 100%;
flex-grow: 1;
}

.nav > li > a
{
font-size: 18px
}

.navbar-brand
{
font-size: 28px;
}

img
{
height: 70px;
width: 70px;
float: right;
margin-top:-20px;
margin-left: 20px;
}

.navbar > .container, .navbar > .container-fluid
{
display: flex;
justify-content: space-between;
}

@media (min-width: 900px)
{
.navbar-toggler
{
display:none;
}
}

.container
{
width: 100%;
}

button
{
background-color: transparent;
}

.bg-primary
{
background-color: transparent;
}
.navbar-toggler-icon
{
background-color: transparent;
display: inline-block;
width: 1.5em;
height: 1.5em;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}

一切似乎都很好,但是当按下按钮时,导航栏(主页 - 服务 - 合作伙伴 - 联系)不会出现在下一行,而是出现在同一行,所有内容都向左移动:https://imgur.com/a/8JU2oKT

有人能告诉我为什么导航栏没有显示在下一行吗?

最佳答案

快速浏览一下您的代码,CSS 似乎不是问题所在,而是 div 的位置问题。尝试将 HTML 替换为:

<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/test.css">

</head>
<body>

<!--Navigation bar-->
<nav class="navbar navbar-custom navbar-fixed-top" id="myNavbar">
<div class="container">
<div class="navbar-brand">
<img src="images/testLogo.png">
</div>
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

</div>
<div id="navbarResponsive" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right" id="ul">
<li class="active"><a href="main.html">Home</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="projects.html">Partners</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</nav>
</body>
</html>

我用里面的实际菜单替换了 div,在容器 div 之外,但仍在导航中。

关于html - bootstrap - 为什么我的导航栏没有出现在下一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51834610/

24 4 0