一、Bootstrap简介

BootStrap是由Twitter推出的前端框架,2011 年八月在 GitHub 上发布,BootStrap是基于Html,Css,Javascript的,可用于快速开发web,是现在主流的前端框架。

Bootstrap的优点有:

1. 移动设备优先:自 Bootstrap 3 起,框架包含了贯穿于整个库的移动设备优先的样式。

2.浏览器支持:所有的主流浏览器都支持 Bootstrap。

3.容易上手:因为Bootstrap是基于 HTML 和 CSS 的基础知识,所以学习使用轻松。

4.响应式设计:Bootstrap 的响应式 CSS 能够自适应于台式机、平板电脑和手机。

二、下载BootStrap

可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本。当您点击这个链接时,将看到如下所示的网页:

您会看到两个按钮:

  • Download Bootstrap:下载 Bootstrap。点击该按钮,您可以下载 Bootstrap CSS、JavaScript 和字体的预编译的压缩版本。不包含文档和最初的源代码文件。
  • Download Source:下载源代码。点击该按钮,您可以直接从 from 上得到最新的 Bootstrap LESS 和 JavaScript 源代码。这个是包含上面的压缩内容再加上源代码

我们下载Download Bootstrap 这个就可以了。

然后这个的文件结构是

已经看到里面是一些CSS 和 JS 还有Glyphicons 的字体。

三、引入到HTML

1.把下载好的BootStrap文件放到项目中。

2.一个引用BootStrap的html模板:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="../js/bootstrap-3.3.5/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="../js/jquery-1.9.1.min.js"></script>
<script src="../js/bootstrap-3.3.5/dist/js/bootstrap.min.js"></script>
</head>
<body> </body>
</html>

在这里,可以看到<Head>..</Head>包含了  jquery.jsbootstrap.min.js 和 bootstrap.min.css 文件,用于让一个常规的 HTML 文件变为使用了 Bootstrap 的模板。

注意: 因为BootStrap 的javascript插件需要引入 jQuery ,所以要另外下载一个Jquery.js,并且要放到bootstrap.min.js的前面。

四、用BootStrap CDN加速点

可以不用下载BootStrap,直接使用一些BootStrap加速点,使用CND加速点的好处:是访问速度更快、加速效果更明显、没有速度和带宽限制、永久免费。

可根据个人喜欢的CDN加速点选用, 这里使用的是百度的静态资源库(http://cdn.code.baidu.com/)上的Bootstrap资源

HTML模板就可以变成了:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/> <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script> <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head>
<body> </body>
</html>

注意: 使用CDN必须有外网才可以。

五、第一个例子_字体图标

上面下载安装BootStrap的时候以经了解过它的目录结构,

在 dist文件夹内的fonts 文件夹内可以找到字体图标,它包含了下列这些文件:

  • glyphicons-halflings-regular.eot
  • glyphicons-halflings-regular.svg
  • glyphicons-halflings-regular.ttf
  • glyphicons-halflings-regular.woff

相关的 CSS 规则写在 dist 文件夹内的 css 文件夹内的 bootstrap.css 和 bootstrap-min.css 文件上。

Bootstrap 捆绑了 200 多种字体格式的字形 这里有BootStrap的字体图标列表http://www.runoob.com/try/demo_source/bootstrap3-glyph-icons.htm

CSS 规则解释

@font-face {
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
} .glyphicon {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
-webkit-font-smoothing: antialiased;
font-style: normal;
font-weight: normal;
line-height: 1;
-moz-osx-font-smoothing: grayscale;
}

所以 font-face 规则实际上是在找到 glyphicons 地方声明 font-family 和位置。

.glyphicon class 声明一个从顶部偏移 1px 的相对位置,呈现为 inline-block,声明字体,规定 font-style 和 font-weight 为 normal,设置行高为 1。除此之外,使用 -webkit-font-smoothing: antialiased 和 -moz-osx-font-smoothing: grayscale; 获得跨浏览器的一致性。

用法

如需使用图标,只需要简单地使用下面的代码即可。

<span class="glyphicon glyphicon-search"></span>
在一个<span></span>标签中加入.class样式即可。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 实例 - 如何使用字形图标(Glyphicons)</title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body> <p>
<a href="#"><span class="glyphicon glyphicon-search">搜索</span></a>
<a href="#" >
<span class="glyphicon glyphicon-fast-backward">首页</span>
</a>
<a href="#">
<span class="glyphicon glyphicon-fast-forward">末页</span>
</a>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-zoom-in">放大</span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-trash">删除</span>
</button>
</p>
<button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-user"></span>用户
</button>
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-user"></span>用户
</button>
<button type="button" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-user"></span> 用户
</button>
</body>
</html>

效果:

其中用户中的 btn-lg   btn-sm   btn-xs 是三个控制大小的样式。

自定义大小和颜色

通过增加或减少图标的字体尺寸,您可以让图标看起来更大或更小。

<button type="button" class="btn btn-primary btn-lg" style="font-size: 60px">
<span class="glyphicon glyphicon-user"></span> 用户
</button>

定制字体颜色

<button type="button" class="btn btn-primary btn-lg" style="color: color:#f00;">
<span class="glyphicon glyphicon-user"></span> 用户
</button>

 

BootStrap学习(1)的更多相关文章

  1. Bootstrap~学习笔记索引

    回到占占推荐博客索引 bootstrap已经用了有段时间了,感觉在使用上还是比较容易接受的,在开发人员用起来上,也还好,不用考虑它的兼容性,手机,平台,PC都可以有效的兼容. bootstrap官方a ...

  2. Bootstrap学习(3)

    Bootstrap 图片  Bootstrap 对图片的支持.Bootstrap 提供了三个可对图片应用简单样式的 class: .img-rounded:添加 border-radius:6px 来 ...

  3. BootStrap学习(2)

    使用Bootstrap添加代码框 可先看:简介.引入.包下载等:http://www.cnblogs.com/0201zcr/p/4900062.html Bootstrap 允许您以两种方式显示代码 ...

  4. Bootstrap 学习(1)

    简介 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. Bootst ...

  5. 前端框架——BootStrap学习

    BootStrap简单总结下:1.栅格系统,能够很好的同时适应手机端和PC端(及传说中的响应式布局) 2.兼容性好 接下来是对BootStrap学习的一些基础案例总结和回顾: 首先引入:bootstr ...

  6. bootstrap学习总结-css样式设计(一)

    由于项目需要,所以打算好好学习下bootstrap框架,之前了解一点,框架总体不难,但涉及到的东西还是很多,想要熟练掌握它,还是要多练练. 一:bootstrap是什么? bs是什么?  即前端页面搭 ...

  7. Bootstrap学习笔记(二) 表单

    在Bootstrap学习笔记(一) 排版的基础上继续学习Bootstrap的表单,编辑器及head内代码不变. 3-1 基础表单 单中常见的元素主要包括:文本输入框.下拉选择框.单选按钮.复选按钮.文 ...

  8. BootStrap学习之先导篇——响应式网页

    Bootstrap学习之前,要知道响应式网页的原理. 1.什么是响应式网页? 一个页面,可以根据浏览设备的不同,以及特性的不同,而自动改变布局.大小等.使得在不同的设备上上都可以呈现优秀的界面. 优点 ...

  9. bootstrap学习笔记之为导航条添加标题、二级菜单及状态 http://www.imooc.com/code/3120

    为导航条添加标题.二级菜单及状态 加入导航条标题 在Web页面制作中,常常在菜单前面都会有一个标题(文字字号比其它文字稍大一些),其实在Bootstrap框架也为大家做了这方面考虑,其通过" ...

  10. bootstrap学习笔记之基础导航条 http://www.imooc.com/code/3111

    基础导航条 在Bootstrap框中,导航条和导航从外观上差别不是太多,但在实际使用中导航条要比导航复杂得多.我们先来看导航条中最基础的一个--基础导航条. 使用方法: 在制作一个基础导航条时,主要分 ...

随机推荐

  1. off by null 实战

    前言 off by null 是一个比较有意思的技术 下面通过 hctf2018 的 heapstrom_zero 实战一波. 相关文件(exp, 题目)位于 https://gitee.com/ha ...

  2. Expo大作战(四十)--expo sdk api之 Calendar,Constants

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  3. springcloud 入门 8 (config配置中心)

    Spring Cloud Config: 配置中心为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件,它就是Spring Cloud Config. 在分布式系统中,由于服务数量巨多, ...

  4. python第六十天-----RabbitMQ

    RabbitMQ消息队列:默认为消息轮循模式,按client端启动是顺序接收 server端 import pika connection = pika.BlockingConnection(pika ...

  5. The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured

    springboot 8080端口被占用报错:The Tomcat connector configured to listen on port 8080 failed to start. The p ...

  6. Memory barrier 简介

    Memory barrier Memory barrier 简介 程序在运行时内存实际的访问顺序和程序代码编写的访问顺序不一定一致,这就是内存乱序访问.内存乱序访问行为出现的理由是为了提升程序运行时的 ...

  7. IDEA 编译 Jmeter 5.0(二次开发)

    windows10 操作系统,jdk1.8,Intellij IDEA 2018,jmeter5.0 1.下载 http://jmeter.apache.org/download_jmeter.cgi ...

  8. MySQL面试题之死锁

    什么是死锁?锁等待?如何优化这类问题?通过数据库哪些表可以监控? 死锁是指两个或多个事务在同一资源上互相占用,并请求加锁时,而导致的恶性循环现象.当多个事务以不同顺序试图加锁同一资源时,就会产生死锁. ...

  9. logstash启动失败的问题追查

    在实验中logstash是作为日志过滤器的作用,日志收集使用的则是filebeat组件.redis作为缓存器,logstash从redis中拉取数据进行过滤并传给elasticsearch组件. 但是 ...

  10. Sudoku(第二次作业)

    这里是github 工具清单: 编程语言:C++ 编程IDE:XCode 效能分析工具:XCode 源代码管理平台:Github PSP2.1 PSP2.1 Personal Software Pro ...