中间带有徽标的两部分 Bootstrap 导航菜单
Two-part Bootstrap navigation menu with logo in the center
我正在使用 nav_walker 在导航栏中创建动态 wordpress 链接。我如何在 wordpress nav_walker:
中实现这样的中心
+-----------------------------+-----------+------------------------------+
+---------------HOME--ABOUT---|-LOGO HERE-|---CONTACT--PROFILE-----------+
+-----------------------------+-----------+------------------------------+
我该怎么做,或者请给我 jsfiddle 来想出那个。
是左右导航的两个nav_walker函数吗?我怎样才能在中心插入导航栏品牌?谁能给我结构。谢谢。
我的代码:
<nav class="navbar navbar-inverse navbar-fixed-top">
<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>
</div>
<div class="navbar-brand navbar-center">
</div>
<?php wp_nav_menu(array(
'menu' => 'primary-1',
'theme_location' => 'primary-1',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse navbar-center',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
?>
</nav>
好的,请尝试使用下面的标记来实现您正在寻找的内容,您还需要调整一些 CSS 以覆盖 bootstrap 的默认样式。
HTML
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<a class="navbar-brand">Your logo</a>
<li><a href="../navbar/">Contact</a></li>
<li><a href="../navbar/">Profile</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
实现你想要的CSS(确保它覆盖默认的bootstrap样式)
.navbar-nav {
float: none;
margin: auto;
max-width: 40%; //adjust to your requirements
}
不久前,我在寻找完全相同的东西,偶然发现了这支笔。
支持 Bryan Willis
Bootstrap 3 Headers 看最后一个例子!
HTML
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar9">
<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 class="brand-centered">
<a class="navbar-brand" href="http://disputebills.com"><img style="margin-right: 10px; padding: 0;" src="http://res.cloudinary.com/disputebills/image/upload/v1462474206/blue-mark_cnzgry.png" alt="Dispute Bills">Dispute Bills
</a>
</div>
<div id="navbar9" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
CSS
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 100%;
padding: 15px;
width: auto;
}
/* EXAMPLE 9 - Center with Flexbox and Text*/
.brand-centered {
display: flex;
justify-content: center;
position: absolute;
width: 100%;
left: 0;
top: 0;
}
.brand-centered .navbar-brand {
display: flex;
align-items: center;
}
如果左右两边的项目数量相同,它会非常简单。只需创建一个列表,将徽标放在中间并执行 text-align: center
。看这里:https://jsfiddle.net/DTcHh/26132/
左右稍有不平就出问题了。我建议创建两个列表,每个列表占屏幕的一半。它们将向中心对齐,并在中心留下一个 space 作为徽标。
在这里查看:https://jsfiddle.net/DTcHh/26133/
html:
<div class="navbar navbar-default">
<div class="logo-wrapper">
<div class="logo"><img class="logo" src="http://www.hsdtaxlaw.com/wp-content/uploads/2016/05/logo_placeholder.png" alt=""></div>
</div>
<div class="half">
<ul class="left-navlist">
<li>Home</li>
<li>About</li>
</ul>
</div>
<div class="half">
<ul class="right-navlist">
<li>Contact</li>
<li>Profile</li>
<li>Maps</li>
</ul>
</div>
</div>
css:
.logo-wrapper {
text-align: center;
margin-bottom: -37px;
}
.logo {
width: 100px;
display: inline-block;
}
.navbar li {
display: inline-block;
padding: 0 10px 10px;
}
.half {
width: 50%;
display: block;
float: left;
}
.right-navlist {
padding-left: 60px;
}
.left-navlist {
text-align: right;
padding-right: 60px;
}
至于如何用wordpress实现这个,相信你得去掉navwalker插件了。只需在 wordpress 中创建两个菜单:left-primary
和 right-primary
。然后用 wp_get_nav_menu_items('left-primary')
迭代它们并按照我的建议构建菜单。这是没有 nav-walker 的 php 代码:
<div class="navbar navbar-default">
<div class="logo-wrapper">
<div class="logo"><img class="logo" src="http://www.hsdtaxlaw.com/wp-content/uploads/2016/05/logo_placeholder.png" alt=""></div>
</div>
<div class="half">
<ul class="left-navlist">
<?
$menu = wp_get_nav_menu_items('left-primary');
foreach ($menu as $menu_item) {
$title = $menu_item->title;
$link = $menu_item->url;
?>
<li href="<?=$link?>"><?=$title?></li>
<?
?
?>
</ul>
</div>
<div class="half">
<ul class="right-navlist">
<?
$menu = wp_get_nav_menu_items('right-primary');
foreach ($menu as $menu_item) {
$title = $menu_item->title;
$link = $menu_item->url;
?>
<li href="<?=$link?>"><?=$title?></li>
<?
?
?>
</ul>
</div>
</div>
我正在使用 nav_walker 在导航栏中创建动态 wordpress 链接。我如何在 wordpress nav_walker:
中实现这样的中心+-----------------------------+-----------+------------------------------+
+---------------HOME--ABOUT---|-LOGO HERE-|---CONTACT--PROFILE-----------+
+-----------------------------+-----------+------------------------------+
我该怎么做,或者请给我 jsfiddle 来想出那个。 是左右导航的两个nav_walker函数吗?我怎样才能在中心插入导航栏品牌?谁能给我结构。谢谢。
我的代码:
<nav class="navbar navbar-inverse navbar-fixed-top">
<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>
</div>
<div class="navbar-brand navbar-center">
</div>
<?php wp_nav_menu(array(
'menu' => 'primary-1',
'theme_location' => 'primary-1',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse navbar-center',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
?>
</nav>
好的,请尝试使用下面的标记来实现您正在寻找的内容,您还需要调整一些 CSS 以覆盖 bootstrap 的默认样式。
HTML
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<a class="navbar-brand">Your logo</a>
<li><a href="../navbar/">Contact</a></li>
<li><a href="../navbar/">Profile</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
实现你想要的CSS(确保它覆盖默认的bootstrap样式)
.navbar-nav {
float: none;
margin: auto;
max-width: 40%; //adjust to your requirements
}
不久前,我在寻找完全相同的东西,偶然发现了这支笔。 支持 Bryan Willis
Bootstrap 3 Headers 看最后一个例子!
HTML
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar9">
<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 class="brand-centered">
<a class="navbar-brand" href="http://disputebills.com"><img style="margin-right: 10px; padding: 0;" src="http://res.cloudinary.com/disputebills/image/upload/v1462474206/blue-mark_cnzgry.png" alt="Dispute Bills">Dispute Bills
</a>
</div>
<div id="navbar9" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
CSS
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 100%;
padding: 15px;
width: auto;
}
/* EXAMPLE 9 - Center with Flexbox and Text*/
.brand-centered {
display: flex;
justify-content: center;
position: absolute;
width: 100%;
left: 0;
top: 0;
}
.brand-centered .navbar-brand {
display: flex;
align-items: center;
}
如果左右两边的项目数量相同,它会非常简单。只需创建一个列表,将徽标放在中间并执行 text-align: center
。看这里:https://jsfiddle.net/DTcHh/26132/
左右稍有不平就出问题了。我建议创建两个列表,每个列表占屏幕的一半。它们将向中心对齐,并在中心留下一个 space 作为徽标。
在这里查看:https://jsfiddle.net/DTcHh/26133/
html:
<div class="navbar navbar-default">
<div class="logo-wrapper">
<div class="logo"><img class="logo" src="http://www.hsdtaxlaw.com/wp-content/uploads/2016/05/logo_placeholder.png" alt=""></div>
</div>
<div class="half">
<ul class="left-navlist">
<li>Home</li>
<li>About</li>
</ul>
</div>
<div class="half">
<ul class="right-navlist">
<li>Contact</li>
<li>Profile</li>
<li>Maps</li>
</ul>
</div>
</div>
css:
.logo-wrapper {
text-align: center;
margin-bottom: -37px;
}
.logo {
width: 100px;
display: inline-block;
}
.navbar li {
display: inline-block;
padding: 0 10px 10px;
}
.half {
width: 50%;
display: block;
float: left;
}
.right-navlist {
padding-left: 60px;
}
.left-navlist {
text-align: right;
padding-right: 60px;
}
至于如何用wordpress实现这个,相信你得去掉navwalker插件了。只需在 wordpress 中创建两个菜单:left-primary
和 right-primary
。然后用 wp_get_nav_menu_items('left-primary')
迭代它们并按照我的建议构建菜单。这是没有 nav-walker 的 php 代码:
<div class="navbar navbar-default">
<div class="logo-wrapper">
<div class="logo"><img class="logo" src="http://www.hsdtaxlaw.com/wp-content/uploads/2016/05/logo_placeholder.png" alt=""></div>
</div>
<div class="half">
<ul class="left-navlist">
<?
$menu = wp_get_nav_menu_items('left-primary');
foreach ($menu as $menu_item) {
$title = $menu_item->title;
$link = $menu_item->url;
?>
<li href="<?=$link?>"><?=$title?></li>
<?
?
?>
</ul>
</div>
<div class="half">
<ul class="right-navlist">
<?
$menu = wp_get_nav_menu_items('right-primary');
foreach ($menu as $menu_item) {
$title = $menu_item->title;
$link = $menu_item->url;
?>
<li href="<?=$link?>"><?=$title?></li>
<?
?
?>
</ul>
</div>
</div>