gpt4 book ai didi

html - 导航栏的定位

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

我很难更改当前导航栏的位置。有谁知道该怎么做才能将其定位在 Logo 下方的中央?我附上了一张我希望导航栏外观的图片。

How I would like the nav bar to be

.navbar.navbar-default {
background-color: #ffffff;
border-color: #ffffff;
padding-top:15px;
padding-bottom:30px;
}
.navbar.navbar-default .navbar-brand {
color: #696969;
}
.navbar.navbar-default .navbar-brand:hover,
.navbar.navbar-default .navbar-brand:focus {
color: #ff9c74;
}
.navbar.navbar-default .navbar-text {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a:focus {
color: #747474;
}
.navbar.navbar-default .navbar-nav > .active > a,
.navbar.navbar-default .navbar-nav > .active > a:hover,
.navbar.navbar-default .navbar-nav > .active > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-nav > .open > a,
.navbar.navbar-default .navbar-nav > .open > a:hover,
.navbar.navbar-default .navbar-nav > .open > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle {
border-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle:hover,
.navbar.navbar-default .navbar-toggle:focus {
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle .icon-bar {
background-color: #292929;
}
.navbar.navbar-default .navbar-collapse,
.navbar.navbar-default .navbar-form {
border:none;
}
.navbar.navbar-default .navbar-link {
color: #292929;
}
.navbar.navbar-default .navbar-link:hover {
color: #696969;
}

.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}

.nav.navbar-nav > li.navbar-left {
font-family: 'Nunito Sans', sans-serif;
font-size: 11.5px;
}

.navbar-brand {
padding: 10px;
}

.navbar-brand>img {
height: 50px;
width: auto
}

@media (min-width: 768px) {
.navbar-brand { display: block; }
.navbar-bar-default .navbar-toggle {text-align: left;}
}

.fa.fa-instagram {
font-size: 18px;
}
.fa.fa-pinterest {
font-size: 18px;
}
.fa.fa-dribbble {
font-size: 18px;
}
.fa.fa-twitter{
font-size: 18px;
}

.banner {
width: 100%;
}

.banner-inner {
max-width:1100px;
margin: 0 auto;
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}


body { padding-top: 90px; }
@media screen (min-width: 468px) and (max-width: 768px) {
body { padding-top: 0px; }
}

.banner-inner>img {
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;
}

.col-1-1> img{
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;

}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<title></title>
<meta name="author" content="">
<link rel="icon" type="image/png" href="img/icon.png"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="css/sticky-footer.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito|Nunito+Sans|Playfair+Display" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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" rel="stylesheet">
<!-- 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>
</head>
<body>
<header>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://"><img onload="this.style.opacity='1';" class= "logo" src="img/logo.png"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="navbar-left"><a href="http://www">TRAVEL</a></li>
<li class="navbar-left"><a href="http://www"> PORTFOLIO </a></li>
<li class="navbar-left"><a href="http://www"> INSPO </a></li>
<li class="navbar-left"><a href="http://www"> ABOUT </a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="right"> <a href="https://www.instagram.com/"><i class="fa fa-instagram"></i></a></li>
<li class="right"> <a href="https://dribbble.com/"><i class="fa fa-dribbble"></i></a></li>
<li class="right"> <a href="https://www.pinterest.com/"><i class="fa fa-pinterest"></i></a></li>
<li class="right"> <a href="https://twitter.com/"><i class="fa fa-twitter"></i></a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</div>
</div>
</header>
<!---End Header-->
<section class="banner">
<div class="banner-inner">
<img onload="this.style.opacity='1';" class="banner" src="img/background.jpg">
</div>
</section>
<!---End Banner-->
<!-- Begin page content -->
<footer class="footer">
<div class="container">
<span class>Copyright &copy; 2017. JH. All rights reserved.</span>
</div>
</footer>
<!---End Footer-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>

最佳答案

您当前的 HTML 无法使用,因此我修改了一些小东西。主要是将您的图片放在它自己的 div 中,给它一个“margin-top: 50px;”,这样它就会在您的模拟节目中下推 Nav。 (为了好玩而放一个有趣的标志 =P。你可以用你的真实标志替换它。)你遇到困难的原因是你还需要用你的代码覆盖 CSS boostrap 默认代码拥有 Logo 。

在桌面中,它现在看起来像您的 Mock。在 Mobile 中, Logo 和汉堡菜单在同一行中看起来仍然不错。 (您没有阐明您希望 Mobile 有什么行为,所以我希望没问题。)

在下方添加代码,我也将其放入 CodePen 中:http://codepen.io/alejandra_quetzalli/pen/YZWMLY?editors=1100

img.navbar-brand {
height: 45px;
margin: 0;
padding: 0;
}
.navbar.navbar-default {
background-color: #ffffff;
border-color: #ffffff;
padding-top:15px;
padding-bottom:30px;
}
.navbar.navbar-default .navbar-brand {
color: #696969;
}
.navbar.navbar-default .navbar-brand:hover,
.navbar.navbar-default .navbar-brand:focus {
color: #ff9c74;
}
.navbar.navbar-default .navbar-text {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a:focus {
color: #747474;
}
.navbar.navbar-default .navbar-nav > .active > a,
.navbar.navbar-default .navbar-nav > .active > a:hover,
.navbar.navbar-default .navbar-nav > .active > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-nav > .open > a,
.navbar.navbar-default .navbar-nav > .open > a:hover,
.navbar.navbar-default .navbar-nav > .open > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle {
border-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle:hover,
.navbar.navbar-default .navbar-toggle:focus {
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle .icon-bar {
background-color: #292929;
}
.navbar.navbar-default .navbar-collapse,
.navbar.navbar-default .navbar-form {
border:none;
margin-top: 50px;
}
.navbar.navbar-default .navbar-link {
color: #292929;
}
.navbar.navbar-default .navbar-link:hover {
color: #696969;
}

.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}

.nav.navbar-nav > li.navbar-left {
font-family: 'Nunito Sans', sans-serif;
font-size: 11.5px;
}

.navbar-brand {
padding: 10px;
}

.navbar-brand>img {
height: 50px;
width: auto
}

@media (min-width: 768px) {
.navbar-brand { display: block; }
.navbar-bar-default .navbar-toggle {text-align: left;}
}

.fa.fa-instagram {
font-size: 18px;
}
.fa.fa-pinterest {
font-size: 18px;
}
.fa.fa-dribbble {
font-size: 18px;
}
.fa.fa-twitter{
font-size: 18px;
}

.banner {
width: 100%;
}

.banner-inner {
max-width:1100px;
margin: 0 auto;
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}


body { padding-top: 90px; }
@media screen (min-width: 468px) and (max-width: 768px) {
body { padding-top: 0px; }
}

.banner-inner>img {
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;
}

.col-1-1> img{
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;

}




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<title></title>
<meta name="author" content="">
<link rel="icon" type="image/png" href="img/icon.png"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="css/sticky-footer.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito|Nunito+Sans|Playfair+Display" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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" rel="stylesheet">
<!-- 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>
</head>
<body>
<header>

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div><img class="navbar-brand" href="http://" onload="this.style.opacity='1';" class= "logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/32877/logo-thing.png"></div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

</div>
<!-- <div><img class="navbar-brand" href="http://" onload="this.style.opacity='1';" class= "logo" src="img/logo.png"></div> -->
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="navbar-left"><a href="http://www">TRAVEL</a></li>
<li class="navbar-left"><a href="http://www"> PORTFOLIO </a></li>
<li class="navbar-left"><a href="http://www"> INSPO </a></li>
<li class="navbar-left"><a href="http://www"> ABOUT </a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="right"> <a href="https://www.instagram.com/"><i class="fa fa-instagram"></i></a></li>
<li class="right"> <a href="https://dribbble.com/"><i class="fa fa-dribbble"></i></a></li>
<li class="right"> <a href="https://www.pinterest.com/"><i class="fa fa-pinterest"></i></a></li>
<li class="right"> <a href="https://twitter.com/"><i class="fa fa-twitter"></i></a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</div>
</div>
</header>
<!---End Header-->
<section class="banner">
<div class="banner-inner">
<img onload="this.style.opacity='1';" class="banner" src="img/background.jpg">
</div>
</section>
<!---End Banner-->
<!-- Begin page content -->
<footer class="footer">
<div class="container">
<span class>Copyright &copy; 2017. JH. All rights reserved.</span>
</div>
</footer>
<!---End Footer-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>

编辑

更新了上面的代码,也根据要求将导航栏链接/图标居中。

<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device=width, initial-scale=1.0">
<title></title>
<meta name="author" content="">
<link rel="icon" type="image/png" href="img/icon.png"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="css/sticky-footer.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito|Nunito+Sans|Playfair+Display" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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" rel="stylesheet">
<!-- 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>
</head>
<body>
<header>

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div><img class="navbar-brand" href="http://" onload="this.style.opacity='1';" class= "logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/32877/logo-thing.png"></div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

</div>
<!-- <div><img class="navbar-brand" href="http://" onload="this.style.opacity='1';" class= "logo" src="img/logo.png"></div> -->
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="navbar-left"><a href="http://www">TRAVEL</a></li>
<li class="navbar-left"><a href="http://www"> PORTFOLIO </a></li>
<li class="navbar-left"><a href="http://www"> INSPO </a></li>
<li class="navbar-left"><a href="http://www"> ABOUT </a></li>
</ul>
<ul class="nav navbar-nav">
<li class="right"> <a href="https://www.instagram.com/"><i class="fa fa-instagram"></i></a></li>
<li class="right"> <a href="https://dribbble.com/"><i class="fa fa-dribbble"></i></a></li>
<li class="right"> <a href="https://www.pinterest.com/"><i class="fa fa-pinterest"></i></a></li>
<li class="right"> <a href="https://twitter.com/"><i class="fa fa-twitter"></i></a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</div>
</div>
</header>
<!---End Header-->
<section class="banner">
<div class="banner-inner">
<img onload="this.style.opacity='1';" class="banner" src="img/background.jpg">
</div>
</section>
<!---End Banner-->
<!-- Begin page content -->
<footer class="footer">
<div class="container">
<span class>Copyright &copy; 2017. JH. All rights reserved.</span>
</div>
</footer>
<!---End Footer-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>



<style>
img.navbar-brand {
height: 45px;
margin: 0;
padding: 0;
}
.navbar.navbar-default {
background-color: #ffffff;
border-color: #ffffff;
padding-top:15px;
padding-bottom:30px;
}
.navbar.navbar-default .navbar-brand {
color: #696969;
}
.navbar.navbar-default .navbar-brand:hover,
.navbar.navbar-default .navbar-brand:focus {
color: #ff9c74;
}
.navbar.navbar-default .navbar-text {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #292929;
}
.navbar.navbar-default .navbar-nav > li > a:hover,
.navbar.navbar-default .navbar-nav > li > a:focus {
color: #747474;
}
.navbar.navbar-default .navbar-nav > .active > a,
.navbar.navbar-default .navbar-nav > .active > a:hover,
.navbar.navbar-default .navbar-nav > .active > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-nav > .open > a,
.navbar.navbar-default .navbar-nav > .open > a:hover,
.navbar.navbar-default .navbar-nav > .open > a:focus {
color: #ff9c74;
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle {
border-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle:hover,
.navbar.navbar-default .navbar-toggle:focus {
background-color: #ffffff;
}
.navbar.navbar-default .navbar-toggle .icon-bar {
background-color: #292929;
}
.navbar.navbar-default .navbar-collapse,
.navbar.navbar-default .navbar-form {
border:none;
margin-top: 50px;
}
#navbar {
text-align: center;
}
ul.navbar-nav {
display: inline-block;
}
.navbar.navbar-default .navbar-link {
color: #292929;
}
.navbar.navbar-default .navbar-link:hover {
color: #696969;
}

.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}

.nav.navbar-nav > li.navbar-left {
font-family: 'Nunito Sans', sans-serif;
font-size: 11.5px;
}

.navbar-brand {
padding: 10px;
}

.navbar-brand>img {
height: 50px;
width: auto
}

@media (min-width: 768px) {
.navbar-brand { display: block; }
.navbar-bar-default .navbar-toggle {text-align: left;}
ul.navbar-nav {
float: none;
}
}
ul.navbar-nav {
float: none;
}
.fa.fa-instagram {
font-size: 18px;
}
.fa.fa-pinterest {
font-size: 18px;
}
.fa.fa-dribbble {
font-size: 18px;
}
.fa.fa-twitter{
font-size: 18px;
}

.banner {
width: 100%;
}

.banner-inner {
max-width:1100px;
margin: 0 auto;
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}

@media (min-width:468px) and (max-width:991px){
.container.navbar-container {
width:100%;
padding:0px;
}
}


body { padding-top: 90px; }
@media screen (min-width: 468px) and (max-width: 768px) {
body { padding-top: 0px; }
}

.banner-inner>img {
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;
}

.col-1-1> img{
opacity:0;
-moz-transition: opacity 2s; /* Firefox 4 */
-webkit-transition: opacity 2s; /* Safari and Chrome */
-o-transition: opacity 2s;
transition: opacity 2s;
}

</style>

关于html - 导航栏的定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42612854/

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