一、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. React.js 新手教程

    正如你能从标题猜到的,这篇文章的目标是给那些有很少编程经验的读者的.比如,像我这样的人:因为迄今为止,我才探索了编程世界6个月.所以,这将是一篇新手村教程! 你只需要拥有对 HTML 和 CSS 的理 ...

  2. AJAX的优点 个人理解记录

    1:对网站性能的提高.例如我只需要刷新页面中购物车的数据,使用ajax时不需要请求整个页面的数据,对于客户端和服务器的压力都会降低, 减少了ISP的负担,服务器的空间和带宽压力都会降低. 2:用户体验 ...

  3. Apache POI导出excel表格

    项目中我们经常用到导出功能,将数据导出以便于审查和统计等.本文主要使用Apache POI实现导出数据. POI中文文档 简介 ApachePOI是Apache软件基金会的开放源码函式库,POI提供A ...

  4. python第九十六天 ---Django(1)

    django 模块 一  安装: pip3 install django 或 python -m pip install django 二  添加环境变量 相关命令: #cmd 下 django-ad ...

  5. nginx、tomcat调优方向及压测网站步骤

    nginx调优方向: 1.所用事件处理模型 2.进程数 3.每个进程的连接数 4.压缩 5.缓存 tomcat调优方向: 1.内存 2.总内存 3.初始申请内存 4.线程内存 5.GC方面 tomca ...

  6. Linux下Sublime Text 3的安装

    1.下载 官网下载 或者直接 #wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3059_x32.tar.bz2 (linux ...

  7. JQuery中$.cookie()方法的使用[转]

    jquery.cookie.js插件: <script type="text/javascript" src="js/jquery-1.6.2.min.js&quo ...

  8. 使用POI读写Word doc文件

    使用POI读写word doc文件 目录 1     读word doc文件 1.1     通过WordExtractor读文件 1.2     通过HWPFDocument读文件 2     写w ...

  9. python六十一课——高阶函数之reduce

    2).reduce(fn,lsd): 参数一:fn --> 函数对象 参数二:lsd --> 序列对象 功能: 先将lsd中的第一和第二个元素去除传入到fn中参与运算, 运算后得到结果,再 ...

  10. margin auto 实现居中,与text-align:center的区别

    本文导读:一个元素在水平方向上所占的长度,由width ,padding ,和margin 决定.这些值中,只有width和margin-left,margin-right可以设为auto,text- ...