gpt4 book ai didi

html - 如何将 Bootstrap 导航栏向右移动?

转载 作者:太空宇宙 更新时间:2023-11-04 01:35:31 24 4
gpt4 key购买 nike

我在 twitter Bootstrap 中使用绝对定位的导航栏,但是当我在我的标签内使用 .pull-right 类和导航栏元素时,导航栏元素保持在左侧。我也尝试过使用 float: right;和文本对齐:右;那些没有用。导航栏的绝对定位会影响这种行为吗?我怎样才能让导航栏元素转到横幅的右侧?

.wrapper {
position: relative;
}

#banner {
height: 50vh;
width: 100vw;
position: relative;
}

#responsive-nav {
background-color: transparent;
position: absolute;
z-index: 2;
}

#logo {
position: absolute;
top: 15px;
left: 60px;
z-index: 1;
}
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mock Up</title>
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- Bootstrap Link -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
<nav class="navbar navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<!-- Collapsing Hamburger Buttons for mobile -->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse" id="responsive-nav">
<ul class="nav navbar-nav pull-right">
<li class="nav-item">
<a href="#about">Home</a>
</li>
<li class="nav-item">
<a href="#work">Projects</a>
</li>
<li class="nav-item">
<a href="#contact">Contact</a>
</li>
</ul>
</div>
<div class="wrapper">
<img class="img-responsive" id="logo" src="https://lh3.google.com/u/0/d/0B7B-ke12S7B2ZS1qSS1wOGJCVzg=w1046-h653-iv1">
<img class="img-responsive" id="banner" src="https://lh3.google.com/u/0/d/0B7B-ke12S7B2SDRjaVpyY3FITFk=w1366-h653-iv1">
</div>
</div>
</div>

</nav>
<script src="https://use.fontawesome.com/bd8b80bd9d.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>

</html>

最佳答案

给您一个解决方案 https://jsfiddle.net/j6sqyru8/

.wrapper {
position: relative;
}

#banner {
height: 50vh;
width: 100vw;
position: relative;
}

#responsive-nav {
background-color: transparent;
position: absolute;
z-index: 2;
}

.navbar-toggle {
z-index: 9;
}

#logo {
position: absolute;
top: 15px;
left: 60px;
z-index: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<!-- Collapsing Hamburger Buttons for mobile -->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse" id="responsive-nav">
<ul class="nav navbar-nav pull-right">
<li class="nav-item">
<a href="#about">Home</a>
</li>
<li class="nav-item">
<a href="#work">Projects</a>
</li>
<li class="nav-item">
<a href="#contact">Contact</a>
</li>
</ul>
</div>
<div class="wrapper">
<img class="img-responsive" id="logo" src="https://lh3.google.com/u/0/d/0B7B-ke12S7B2ZS1qSS1wOGJCVzg=w1046-h653-iv1">
<img class="img-responsive" id="banner" src="https://lh3.google.com/u/0/d/0B7B-ke12S7B2SDRjaVpyY3FITFk=w1366-h653-iv1">
</div>
</div>
</div>
</nav>

希望对您有所帮助。

关于html - 如何将 Bootstrap 导航栏向右移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46298790/

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