gpt4 book ai didi

html - 中心的 Bootstrap 导航 Logo

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

我尝试设计一个居中的 Logo 导航,但我遇到了一些输出问题

.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}

@media (min-width: 768px) {
.navbar-nav {
position: relative;
right: -50%;
}
.navbar-nav > li {
position: relative;
left: -50%;
}
.navbar-nav > li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}

@media (min-width: 992px) {
.navbar-nav > li a {
padding: 0 40px;
}
}

@media (min-width: 1200px) {
.navbar-nav > li a {
padding: 0 50px;
}
}

/////

<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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 hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="./about-us">Who We Are</a></li>
<li><a href="./menu">Our Food</a></li>
<li class="hidden-xs"><a href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a></li>
<li><a href="./book">Book a Table</a></li>
<li><a href="./promotions">Promotions</a></li>
</ul>
</div>
</div>
</nav>

The same display error can be seen at codepen also

此外,在 http://codepen.io/anon/pen/egqxjW 进行演示

导致空白的问题是什么?

PS:有没有更好的方法得到同样的结果?我应该怎么做才能在源代码中只包含一次 Logo ?

最佳答案

right: -50%;ul 向右移动了 50%。它的宽度保持不变(容器的 100%),并且向右移动了 50%,因此 ul 的 50% 在容器之外,从屏幕中渗出。

我做了一些更改以实现您想要的相同结果,使用 text-align: centerdisplay: inline-block 代替。它们在 CSS 中标有/* change */。

@import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );

.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}

.navbar-brand {
padding: 0 15px;
height: 96px;
}

@media (min-width: 768px) {
ul.navbar-nav {
position: relative;
float: none;
/* change */
text-align: center;
/* change */
}
ul.navbar-nav>li {
position: relative;
display: inline-block;
/* change */
vertical-align: middle;
float: none;
}
ul.navbar-nav>li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}

@media (min-width: 992px) {
.navbar-nav>li a {
padding: 0 40px;
}
}

@media (min-width: 1200px) {
.navbar-nav>li a {
padding: 0 50px;
}
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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 hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="./about-us">Who We Are</a></li>
<li><a href="./menu">Our Food</a></li>
<li class="hidden-xs">
<a href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</li>
<li><a href="./book">Book a Table</a></li>
<li><a href="./promotions">Promotions</a></li>
</ul>
</div>
</div>
</nav>

关于html - 中心的 Bootstrap 导航 Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42377877/

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