Python百日进阶-WEB开发】Day158 - 前端基础 之 BootStrap(三)

本文介绍Bootstrap框架中的常用样式,包括排版、列表、表格等元素的样式设置方法,以及缩略图和面板组件的使用技巧。

三、常用样式

3.1 排版

3.1.1 标题

Bootstrap和普通的HTML页面一样,定义标题都是使用标签h1到h6,只不过 Bootstrap覆盖了其默认的样式,使用其在所有浏览器下显示的效果一样。为了让非标题元素和标题使用相同的样式,还特意定义了.h1~.h6 六个类名。同时后面可以紧跟着一行小的副标题或使用.small 。

<!-- 标题 ,bootstrap对h1到h6进行了覆盖,提供了.h1到.h6类名--->
<h1>标题1 <small>副标题</small></h1>
<h2>标题2<span class="small">副标题</span></h2>
<h3>标题3</h3>
<div class="h1">类似标题1</div>

在这里插入图片描述

3.1.2 段落

段落是排版中另一个重要元素之一。通过.lead来突出强调内容(其作用就是增大文本字号,加粗文本,而且对行高和 margin也做相应的处理。可以使用以下标签给文本做突出样式处理:

<p>普通段落</p>
<p class="lead">加了lead类名的段落
	<small>这几个字变小点</small>lead段落
	<b>加粗样式</b>lead段落
	<strong>加粗样式</strong>lead段落
	<i>斜体字样式</i>lead段落
	<em>斜体字样式</em>
</p>

在这里插入图片描述

3.1.3 强调

定义了一套类名,这里称其为强调类名这些强调类都是通过颜色来表示强调,具本说明如下:
.text-muted:提示,使用浅灰色(#999)
.text-primary:主要,使用蓝色(#428bca)
.text-success:成功,使用浅绿色(#3c763d)
.text-info:通知信息,使用浅蓝色(#31708f)
.text-warning:警告,使用黄色(#8a6d3b)
.text-danger:危险,使用褐色(#a94442)

<!-- 强调 -->
<div class="text-muted"><h3>提示text-muted效果</h3></div>
<div class="text-primary"><h3>主要text-primary效果</h3></div>
<div class="text-success"><h3>成功tex-success效果</h3></div>
<div class="text-info"><h3>信息tex-info效果</h3></div>
<div class="text-warning"><h3>警告tex-warning效果</h3></div>
<div class="text-danger"><h3>危险text-danger效果</h3></div>

在这里插入图片描述

3.1.4 对齐效果

在CSS中常常使用text-align来实现文本的对齐风格的设置,其中主要有四种风格:
左对齐,取值left;居中对齐,取值center;右对齐,取值 right;两端对齐,取值 justify
为了简化操作,方便使用, Bootstrap通过定义四个类名来控制文本的对齐风格:
text-left:左对齐 text-center:居中对齐 text-right:右对齐 text-justify:两端对齐。

<!-- 对齐效果 -->
<div class="col-md-6" style="background-color: darkkhaki;">
	<p style="text-align: center;" class="h3">原生css样式:居中对齐</p>
	<p class="text-left h3">text-left:左对齐</p>
	<p class="text-center h3">text-center:居中对齐</p>
	<p class="text-right h3">text-right:右对齐</p>
	<p class="text-justify h3">
		text-justify:两端对齐效果展示,在CSS中常常使用text-align来实现文本的对齐风格的设置,其中主要有四种风格:
		左对齐,取值left;居中对齐,取值center;右对齐,取值 right;两端对齐,取值 justify
		为了简化操作,方便使用, Bootstrap通过定义四个类名来控制文本的对齐风格:
		text-left:左对齐	text-center:居中对齐	text-right:右对齐	text-justify:两端对齐。
	</p>
	<p class="h3">
		没有两端对齐效果展示,在CSS中常常使用text-align来实现文本的对齐风格的设置,其中主要有四种风格:
		左对齐,取值left;居中对齐,取值center;右对齐,取值 right;两端对齐,取值 justify
		为了简化操作,方便使用, Bootstrap通过定义四个类名来控制文本的对齐风格:
		text-left:左对齐	text-center:居中对齐	text-right:右对齐	text-justify:两端对齐。
	</p>
</div>

在这里插入图片描述

3.1.5 列表

在HTML文档中,列表结构主要有三种:

  • 无序列表(ul>li)
  • 有序列表(ol>li)
  • 定义列表(dl>dt df>dd)
3.1.5.1 去点列表 class=“list-unstyled”
3.1.5.2 内联列表 class=“list-inline”

把垂直列表换成水平列表,而且去掉项目符号(编号),保持水平显示也可以说内联列表就是为制作水平导航而生。

3.1.5.3 定义列表

在原有的基础加入了一些样式,使用样式 class=“dl-horizontal”制作水平定义列表:当标题宽度超过160px时,将会显示三个省略号。

<!-- 列表 -->
<div class="col-md-6 h4" style="background-color: #F7ECB5;">
	<ul>
		<li>无序列表1</li>
		<li>无序列表2</li>
		<li>无序列表3</li>
	</ul>
	<ol>
		<li>有序列表1</li>
		<li>有序列表2</li>
		<li>有序列表3</li>
	</ol>
	<dl>
		<dt>定义列表标题</dt>
		<dd>定义列表1</dd>
		<dt>定义列表标题</dt>
		<dd>定义列表3</dd>
	</dl>
	<dl class="dl-horizontal">
		<dt>制作水平定义列表:当标题宽度超过160px时,将会显示三个省略号</dt>
		<dd>定义列表1</dd>
		<dd>定义列表2</dd>
		<dd>定义列表3</dd>
	</dl>
	<ul class="list-unstyled">
		<li>无序去点列表1</li>
		<li>无序去点列表2</li>
		<li>无序去点列表3</li>
	</ul>
	<ul class="list-inline">
		<li><a href="#">首页</a></li>
		<li><a href="#">java学堂</a></li>
		<li><a href="#">python学院</a></li>
	</ul>
</div>

在这里插入图片描述

3.1.6 代码

一般在个人博客上使用的较为频繁,用于显示代码的风格。在 Bootstrap主要提供了三种代码风格:

  • 使用来显示单行内联代码
  • 使用
    来显示多行块代码
    样式:pre-scrollable(height,max- height高度固定为340px超过存在滚动条)
  • 使用来显示用户输入代码如快捷键
3.1.6.1.单行内联代码

this is a simple code

3.1.6.2.快捷键

使用ctr+s保存

#### 3.1.6.3.多行块代码
<!-- 代码 -->
<div class="col-md-7" style="background-color: lightblue;">
	这行没有代码风格:print(f'成功列表{send_success}')  <br>
	<code>
		单行内联代码
		所有代码行显示在一行
	</code>
	<p>快捷键:使用<kbd>ctrl+s</kbd>保存</p>
	<!-- pre 代码会保留原有的格式,包括空格和回车 -->
	<pre class="pre-scrollable">
		<h2>显示html代码,需要使用字符实体</h2>
		
		&lt;h2&gt;显示html代码,需要使用字符实体&lt;/h2&gt;
		
		main.tb_concat_result.append(f' ^O^ ^O^ ^O^ ^O^ 邮件发送完毕! ^O^ ^O^ ^O^ ^O^ ')
		
		main.tb_concat_result.append(f'成功列表{send_success}')
		
		main.tb_concat_result.append(f'失败列表{send_fail}')
		
		# main.btn_concat_mail.setVisible(False)
		
		print(f'成功列表{send_success}')
		
		print(f'失败列表{send_fail}')
	</pre>
</div>

在这里插入图片描述

3.1.7 表格

3.1.7.1 表格样式

Bootstrap为表格提供了1种基础样式和4种附加样式,以及1个支持响应式的表格。在使用 Bootstrap的表格过程中,只需要添加对应的类名就可以得到不同的表格风格:

  1. 基础样式
  • table:基础表格
  1. 附加样式
  • .table-striped:斑马线表格,隔行换色
  • .table-bordered:带边框的表格
  • .table-hover:鼠标悬停高亮的表格
  • .table-condensed:紧凑型表格,单元格没内距或者内距较其他表格的内距小
3.1.7.2 tr、th、td样式

提供了五种不同的类名,每种类名控制了行的不同背景颜色

描述
.active将悬停的颜色应用在行或者单元格上
.success表示成功的操作
.info表示信息变化的操作
.warning表示一个警告的操作
.danger表示一个危险的操作
<!-- 表格 -->
<div class="col-md-7" style="background-color: powderblue;">
	<table class="table table-bordered table-hover">
		<tr class="active">
			<td>JavaSE</td>
			<td>数据库</td>
			<td>JavaScript</td>
		</tr>
		<tr class="success">
			<td>面向对象</td>
			<td>oracle</td>
			<td>json</td>
		</tr>
		<tr class="info">
			<td>数组</td>
			<td>mysql</td>
			<td>ajax</td>
		</tr>
		<tr class="warning">
			<td>面向对象</td>
			<td>oracle</td>
			<td>json</td>
		</tr>
		<tr class="danger">
			<td>数组</td>
			<td>mysql</td>
			<td>ajax</td>
		</tr>
	</table>
</div>

在这里插入图片描述

3.2 缩略图

缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。

<!-- 缩略图 -->
			<div class="col-md-10">
				<div class="container">
					<div class="col-md-3">
						<!-- 缩略图div -->
						<div class="thumbnail">
							<img src="img/timg.jpg" alt="...">
							<h3 class="glyphicon glyphicon-earphone col-md-offset-1">缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
				</div>
			</div> <br>

在这里插入图片描述

3.3 面板

默认的panel组件所做的只是设置基本的边框(border)和内补(padding)来包含内容。

  • class="panel-default:默认样式
  • class=“panel-heading”:面板头
  • class=“panel–body”:面板主体内容
<div class="col-md-12">
	<!-- 面板 panel -->
	<div class="panel panel-success">
		<div class="panel-heading">
			<h2 class="text-center">明星合集</h2>
		</div>
		<div class="panel-body">
			<!-- 缩略图 -->
			<div class="col-md-12">
				<div class="container">
					<div class="col-md-3">
						<!-- 缩略图div -->
						<div class="thumbnail">
							<img src="img/timg.jpg" alt="...">
							<h3 class="glyphicon glyphicon-earphone col-md-offset-1">缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
					<div class="col-md-3">
						<div class="thumbnail">
							<img src="img/timg.jpg" >
							<h3>缩略图</h3>
							<p>缩略图在电商类的网站很常见,最常用的地方就是产品列表页面。缩略图的实现是配合网格系统一起使用。同时还可以让缩略图配合标题、描述内容,按钮等。</p>
							<button type="button" class="btn btn-primary glyphicon glyphicon-heart col-md-offset-1"> 好用</button>
							<button type="button" class="btn btn-danger glyphicon glyphicon-phone col-md-offset-1"> 不好用</button>
						</div>
					</div>
				</div>
			</div> <br>
		</div>
	</div>
</div>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

岳涛@泰山医院

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

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

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

打赏作者

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

抵扣说明:

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

余额充值