Bootstrap——导航栏

一、导航栏

1.基本

在这里插入图片描述

导航栏需要使用.navbar 来定义,并使用 .navbar-expand{-sm|-md|-lg|-xl} 用于响应式布局以及使用配色方案Class 。

<nav class="navbar navbar-expand-lg bg-light">
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>
	<ul class="navbar-nav">
		<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
		<li class="nav-item dropdown">
			<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">城市</a>
			<div class="dropdown-menu">
				<a href="#" class="dropdown-item">北京</a>
				<div class="dropdown-divider"></div>
				<a href="#" class="dropdown-item">深圳</a>
			</div>
		</li>
	</ul>
	<!-- <div class="navbar-nav">
		<a href="#" class="nav-item nav-link">入门</a>
		<a href="#" class="nav-item nav-link">布局</a>
	</div> -->
</nav>

2.表单

在导航栏中使用 .form-inline放置各种表单控制元件和组件

<nav class="navbar bg-light mt-5">
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>

	<form action="#" class="form-inline">
		<!-- <input type="search" class="form-control mr-sm-2" placeholder="Search">
		<button type="submit" class="btn btn-outline-success mt-2 mt-sm-0">Search</button> -->

		<div class="input-group">
			<div class="input-group-prepend">
				<span class="input-group-text">@</span>
			</div>
			<input type="search" class="form-control mr-sm-2" placeholder="Search">
		</div>
		<button type="submit" class="btn btn-outline-success mt-2 mt-sm-0">Search</button>
	</form>
</nav>

在这里插入图片描述

3.文本处理

可以使用.navbar-text选择器来包裹文字-这已经对文本字符串的垂直对齐、水平间距作了处理优化。

<nav class="navbar navbar-expand-lg bg-light mt-5">
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>
	<ul class="navbar-nav mr-auto">
		<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
		<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
		<li class="nav-item"><a href="#" class="nav-link">内容</a></li>
	</ul>
	<span class="navbar-text">这是导航当中的文本</span>
</nav>

在这里插入图片描述

4.配色方案

<nav class="navbar navbar-expand-lg bg-dark navbar-dark mt-5">
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>
	<ul class="navbar-nav mr-auto">
		<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
		<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
		<li class="nav-item"><a href="#" class="nav-link">内容</a></li>
	</ul>
	<form action="#" class="form-inline">
		<input type="search" class="form-control mr-sm-2" placeholder="Search">
		<button type="submit" class="btn btn-outline-success mt-2 mt-sm-0">Search</button>
	</form>
</nav>

在这里插入图片描述

5.居中容器

你可以把导航条包裹在一个 .container容器中,从而使之在网页中呈现居中效果

<div class="container">
	<nav class="navbar navbar-expand-lg bg-dark navbar-dark mt-5">
		<a href="#" class="navbar-brand">
			<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
				class="align-top"> Bootstrap
		</a>
		<ul class="navbar-nav mr-auto">
			<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
			<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
			<li class="nav-item"><a href="#" class="nav-link">内容</a></li>
		</ul>
		<form action="#" class="form-inline">
			<input type="search" class="form-control mr-sm-2" placeholder="Search">
			<button type="submit" class="btn btn-outline-success mt-2 mt-sm-0">Search</button>
		</form>
	</nav>
</div>

在这里插入图片描述

6.定位

<nav class="navbar navbar-light bg-light fixed-top">
	<a href="#" class="navbar-brand">因定在顶部</a>
</nav>
<nav class="navbar navbar-light bg-light fixed-bottom">
	<a href="#" class="navbar-brand">因定在底部</a>
</nav>
<nav class="navbar navbar-light bg-light sticky-top">
	<a href="#" class="navbar-brand">粘性定位在浏览器的顶部</a>
</nav>

7.响应式

当内容在按钮后面折叠时,导航栏可以使用 .navbar-toggler、.navbar-collapse 和 .navbar-expand{-sm|-md|-lg|-xl}的 class样式来更改,结合其它常用样式,你可以根据需要定义显示或隐藏特定元素。

<nav class="navbar navbar-expand-md bg-success navbar-dark mt-5">
	<button class="navbar-toggler" data-toggle="collapse" data-target="#navbar">
		<span class="navbar-toggler-icon"></span>
	</button>
	<div class="collapse navbar-collapse" id="navbar">
		<a href="#" class="navbar-brand">
			<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
				class="align-top"> Bootstrap
		</a>
		<ul class="navbar-nav mr-auto">
			<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
			<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
		</ul>
		<form action="#" class="form-inline">
			<input type="search" class="form-control mr-sm-2" placeholder="Search">
			<button type="submit" class="btn btn-outline-light mt-2 mt-sm-0">Search</button>
		</form>
	</div>
</nav>

在这里插入图片描述
在这里插入图片描述

8.拓展

<!-- 左侧是logo,右侧是按钮 -->
<nav class="navbar navbar-expand-md bg-success navbar-dark mt-5">
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>
	<button class="navbar-toggler" data-toggle="collapse" data-target="#navbar1">
		<span class="navbar-toggler-icon"></span>
	</button>
	<div class="collapse navbar-collapse" id="navbar1">
		<ul class="navbar-nav mr-auto">
			<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
			<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
			<li class="nav-item"><a href="#" class="nav-link">内容</a></li>
		</ul>

		<form action="#" class="form-inline">
			<input type="search" class="form-control mr-sm-2" placeholder="Search">
			<button type="submit" class="btn btn-outline-light mt-2 mt-sm-0">Search</button>
		</form>
	</div>
</nav>
<!-- 左侧是按钮,右侧是logo -->
<nav class="navbar navbar-expand-md bg-success navbar-dark mt-5">
	<button class="navbar-toggler" data-toggle="collapse" data-target="#navbar2">
		<span class="navbar-toggler-icon"></span>
	</button>
	<a href="#" class="navbar-brand">
		<img src="http://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg" alt="" width="30"
			class="align-top"> Bootstrap
	</a>
	<div class="collapse navbar-collapse" id="navbar2">
		<ul class="navbar-nav mr-auto">
			<li class="nav-item"><a href="#" class="nav-link">入门</a></li>
			<li class="nav-item"><a href="#" class="nav-link">布局</a></li>
			<li class="nav-item"><a href="#" class="nav-link">内容</a></li>
		</ul>

		<form action="#" class="form-inline">
			<input type="search" class="form-control mr-sm-2" placeholder="Search">
			<button type="submit" class="btn btn-outline-light mt-2 mt-sm-0">Search</button>
		</form>
	</div>
</nav>

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞羽逐星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值