1、HTML

2、理解Bootstrap

HTML元素告诉浏览器,他要表现的是什么类型的内容,当他们不提供任何关于如何显示内容的信息。如何显示内容的信息,由CSS提供。

本书仅包含足够的信息,让你查看AngularJS特性,和Bootstrap的样式。要演示基本bootstrap的特性,在angularjs文件夹下新建bootstrap.html

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<link href="bootstrap.css" rel="stylesheet"
/>

<link href="bootstrap-theme.css" rel="stylesheet"
/>

</head>

<body>

<div class="panel">

<h3 class="panel-heading">Button Styles</h3>

<button class="btn">Basic Button</button>

<button class="btn btn-primary">Primary</button>

<button class="btn btn-success">Success</button>

<button class="btn btn-warning">Warning</button>

<button class="btn btn-info">Info</button>

<button class="btn btn-danger">Danger</button>

</div>

<div class="well">

<h3 class="panel-heading">Button Sizes</h3>

<button class="btn btn-large btn-success">Large Success</button>

<button class="btn btn-warning">Standard Warning</button>

<button class="btn btn-small btn-danger">Small Danger</button>

</div>

<div class="well">

<h3 class="panel-heading">Block Buttons</h3>

<button class="btn btn-block btn-large btn-success">Large Block Success</button>

<button class="btn btn-block btn-warning">Standard Block Warning</button>

<button class="btn btn-block btn-small btn-info">Small Block Info</button>

</div>

</body>

</html>

2.1、应用基本的Bootstrap classes

Bootstrap样式,通过class属性应用。

<div class="panel">

作者设置class的属性为panel,他是Bootstrap定义的多个CSS classes中的一个。这里有三种基本样式classes:

Bootstrap Class

Description

panel

一个圆角边框的panel。panel可以有一个header和一个footer.

panel-heading

为panel创建一个heading

btn

创建一个button

well

使用inset 效果组织元素

提示:并不是所有的Bootstrap样式都需要使用class属性。h1-h6字号,自动应用样式。

2.1.1、修改样式上下文

Bootstrap定义了一组style context classes。这些classes结合一个基本的Bootstrap 样式class,hyphen,primary,success,waring,info ,danger来使用。

<button class="btn btn-primary">Primary</button>

上下文classes必须应用于基本class,这就是为什么button元素既有btn,也有btn-primary classes。你不是必须使用上下文class,他们是可选的。

2.1.2、修改尺寸

可以通过使用size修改class,来修改元素。他们和一个基本class名,hyphen,lg,sm等一起用,

<button class="btn btn-lgbtn-success">Large Success</button>

你可以应用btn-block class,来创建一个button,它可有一个可用的垂直空间填充。

<button class="btn btn-blockbtn-lg btn-success">Large Block Success</button>

2.2、为Table的样式使用Bootstrap

Bootstrap Class

description

table

为table元素和它的内容生成样式

table-striped

应用alternate-row

table-bordered

为所有行和列应用边框

table-hover

当鼠标hovers over在表中的一个行上,显示不同的样式

table-condensed

减少table里的空间,来创建一个更紧凑的布局

所有这些classes都直接应用在table元素上。

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<link href="bootstrap.css" rel="stylesheet"
/>

<link href="bootstrap-theme.css" rel="stylesheet"
/>

</head>

<body>

<div class="panel">

<h3 class="panel-heading">Standard Table with Context</h3>

<table class="table">

<thead>

<tr><th>Country</th><th>Capital City</th></tr>

</thead>

<tr class="success"><td>United Kingdom</td><td>London</td></tr>

<tr class="danger"><td>France</td><td>Paris</td></tr>

<tr><td>Spain</td><td class="warning">Madrid</td></tr>

</table>

</div>

<div class="panel">

<h3 class="panel-heading">Striped, Bordered and Highlighted Table</h3>

<table class="table table-striped table-bordered table-hover">

<thead>

<tr><th>Country</th><th>Capital City</th></tr>

</thead>

<tr><td>United Kingdom</td><td>London</td></tr>

<tr><td>France</td><td>Paris</td></tr>

<tr><td>Spain</td><td>Madrid</td></tr>

</table>

</div>

</body>

</html>

2.2.1、确保合适的Table结构

注意,作者用了thead元素。浏览器会给table元素下的第一个tr元素,用于thead。

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<link href="bootstrap.css" rel="stylesheet"
/>

<link href="bootstrap-theme.css" rel="stylesheet"
/>

</head>

<body>

<div class="panel">

<h3 class="panel-heading">Striped, Bordered and Highlighted Table</h3>

<table class="table table-striped table-bordered table-hover">

<tr><th>Country</th><th>Capital City</th></tr>

<tr><td>United Kingdom</td><td>London</td></tr>

<tr><td>France</td><td>Paris</td></tr>

<tr><td>Spain</td><td>Madrid</td></tr>

</table>

</div>

</body>

</html>

这个例子没有thead元素,这意味着,header row会被添加浏览器自动创建到tbody元素上。

2.3、使用Bootstrap来创建一个表单

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<link href="bootstrap.css" rel="stylesheet"
/>

<link href="bootstrap-theme.css" rel="stylesheet"
/>

</head>

<body>

<div class="panel">

<h3 class="panel-header">

Form Elements

</h3>

Figure 4-5.  The effect of combining header and body rows in a table

CHAPTer 4 ■HTML And BooTSTrAPCSS PrIMer

68

<div class="form-group">

<label>Name:</label>

<input name="name" class="form-control"
/>

</div>

<div class="form-group">

<label>Email:</label>

<input name="email" class="form-control"
/>

</div>

<div class="radio">

<label>

<input type="radio" name="junkmail" value="yes" checked />

Yes, send me endless junk mail

</label>

</div>

<div class="radio">

<label>

<input type="radio" name="junkmail" value="no"
/>

No, I never want to hear from you again

</label>

</div>

<div class="checkbox">

<label>

<input type="checkbox"
/>

I agree to the terms and conditions.

</label>

</div>

<input type="button" class="btn btn-primary" value="Subscribe"
/>

</div>

</body>

</html>

通过给一个包含label和input的div元素使用form-group class,来应用基本的表单样式。

<div class="form-group">

<label>Email:</label>

<input name="email" class="form-control"
/>

</div>

Bootstrap样式,label在input元素的上方显示,input元素拥有100%的水平可用空间。

提示:label元素用于包含描述文本,input元素与用于其他类型的input元素有不同的结构。

2.4、使用Bootstrap来创建Grids

Bootstrap提供的样式classes,可以用于创建不同种类的grid布局,用于响应式布局。

<!DOCTYPE html>

<html
xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<link
href="bootstrap.css"
rel="stylesheet"
/>

<link
href="bootstrap-theme.css"
rel="stylesheet"
/>

<style>

#gridContainer {padding: 20px;}

.grid-row > div { border: 1px solid lightgrey; padding: 10px;

background-color: aliceblue; margin: 5px 0; }

</style>

</head>

<body>

<div
class="panel">

<h3
class="panel-header">

Grid Layout

</h3>

<div
id="gridContainer">

<div
class="row grid-row">

<div
class="col-xs-1">1</div>

<div
class="col-xs-1">1</div>

<div
class="col-xs-2">2</div>

<div
class="col-xs-2">2</div>

<div
class="col-xs-6">6</div>

</div>

<div
class="row grid-row">

<div
class="col-xs-3">3</div>

<div
class="col-xs-4">4</div>

<div
class="col-xs-5">5</div>

</div>

<div
class="row grid-row">

<div
class="col-xs-6">6</div>

<div
class="col-xs-6">6</div>

</div>

<div
class="row grid-row">

<div
class="col-xs-11">11</div>

<div
class="col-xs-1">1</div>

</div>

<div
class="row grid-row">

<div
class="col-xs-12">12</div>

</div>

</div>

</div>

</body>

</html>

2.4.1、Table VS Grids

Table用于扁平的数据,经常用于在grid中布局内容。一般,你应该给grid中的内容使用CSS布局,因为table与目前分离内容的原则相违背。CSS3包含grid布局,但它还没有在主流浏览器中实现。最好的选项,是使用CSS框架,像Bootstrap。

在作者自己的项目中,有时由于客户端和web app不接受CSS框架,不支持最新的CSS3布局。在这种状况下,作者使用一个table元素,来创建一个grid布局。

2.4.2

Bootstrap grid布局系统,用起来很简单。你可以给div元素应用一个row class,来指定一个列。他会为div元素包含的内容,配置grid布局。

你可以通过col-xs,指定列的子元素占据多少列。

Bootstrap不会给row中的元素应用任何样式,所以作者使用style元素,创建一个自定义CSS样式,设置背景颜色,行之间的间隔,添加一个边框。

<div class="row grid-row">

2.4.3创建响应式Grids

响应式Grids,基于浏览器窗口的尺寸,调整布局。响应式grids,主要用来允许移动设备和桌面设备显示相同的内容,有更好的屏幕可用空间。要创建一个响应式grid,用下面表中的一个classes,替换每个cells的col-* class。

Bootstrap Class

Description

Col-sm-*

当屏幕宽度大于768像素时,Grid cell水平显示

Col-md-*

当屏幕宽度大于940像素时,Grid cell水平显示

Col-lg-*

当屏幕宽度大于1170像素时,Grid cell水平显示

当屏幕宽度低于class支持的宽度,grid row的 cell 会垂直排列,而不是水平。

<!DOCTYPE html>

<html
xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Bootstrap Examples</title>

<meta
name="viewport"
content="width=device-width, initial-scale=1">

<link
href="bootstrap.css"
rel="stylesheet"
/>

<link
href="bootstrap-theme.css"
rel="stylesheet"
/>

<style>

#gridContainer { padding: 20px; }

.grid-row > div { border: 1px solid lightgrey;

padding: 10px; background-color: aliceblue; margin: 5px 0; }

</style>

</head>

<body>

<div
class="panel">

<h3
class="panel-header">

Grid Layout

</h3>

<div
id="gridContainer">

<div
class="row grid-row">

<div
class="col-sm-3">3</div>

<div
class="col-sm-4">4</div>

<div
class="col-sm-5">5</div>

</div>

<div
class="row grid-row">

<div
class="col-sm-6">6</div>

<div
class="col-sm-6">6</div>

</div>

<div
class="row grid-row">

<div
class="col-sm-11">11</div>

<div
class="col-sm-1">1</div>

</div>

</div>

</div>

</body>

</html>

我使用col-sm-*,替换之前的col-xs*。当浏览器窗体宽度大于768像素时,水平排列,小于时,垂直排列。

提示:注意作者加了meta元素。该元素告诉移动设备浏览器,以实际尺寸显示内容。没有meta元素的话,许多移动设备浏览器会一缩放的形式,显示桌面版网页,用户需要放大才能看明细。简而言之,当有移动设备访问时,你需要添加一个meta元素。查看作者的The Definitive Guide to HTML5 这本书,有详细说明。

 

 

4.1HTML和Bootstrap css精华的更多相关文章

  1. Bootstrap.css 中请求googleapis.com/css?family 备忘录

    问题描述: Web中引入bootstrap.css中头部有访问Google服务器的请求 @import url("//fonts.googleapis.com/css?family=Open ...

  2. Bootstrap CSS 栅格、代码和表格

    一.bootstrap栅格 Bootstrap 提供了一套响应式.移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. Bootstrap 网格系统(G ...

  3. Bootstrap CSS概览代码文字标注篇

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. Bootflat – 基于 Bootstrap CSS 框架的扁平化界面

    Bootflat 是一个开源的扁平化的 UI 工具包,基于 Bootstrap 3.1.0 CSS 框架.它为 Web 开发人员提供了一个创建优雅的 Web 应用程序的更快,更容易和更少的重复任务的途 ...

  5. Bootstrap CSS 描述

    <!DOCTYPE html><html lang="zh-CN"><head> <!--定于内容,和内容的编码格式--> < ...

  6. (二)Bootstrap CSS 概览

    在这一章中,我们将讲解 Bootstrap 底层结构的关键部分,包括我们让 web 开发变得更好.更快.更强壮的最佳实践. HTML 5 文档类型(Doctype) Bootstrap 使用了一些 H ...

  7. bootstrap.css.map这个文件有何用处?该怎能使用它?

    . ├── bootstrap.css ├── bootstrap.css.map ├── bootstrap.min.css ├── bootstrap-theme.css ├── bootstra ...

  8. bootstrap css选择不同的宽度

    刚开始使用bootstrap css开源项目.遇到一个问题,默认的input 宽度太大,需要找小一点的. 其实只需要在input tag中选用预定义的较小的宽度即可.比如: <input typ ...

  9. angular 实现modal windows效果(即模态窗口,半透明的遮罩层),以及bootstrap(css,components,js)的初步学习

    废话不说,直接上代码.可直接看效果,对着分析..今天算是bootstrap 入门了,开心.. 突然居然很多事情就是那样,不要太多的畏惧,迈出第一步其实就成功了一半了. <html ng-app= ...

随机推荐

  1. svn更新项目时遇到被锁住的问题

    来自:http://blog.csdn.net/woshixuye/article/details/7776742 遇到问题 我们用svn更新某个项目的时候,有时候会遇到一些什么文件夹被locked等 ...

  2. IIS应用程序池添加ASP.NET v4.0

    可能在安装.NET Framewrok 4.0之前,IIS就已经装好了,结果在IIS的应用程序池中只有.NET 2.0的Classic .NET AppPool和DefaultAppPool.在使用v ...

  3. javascript设计模式学习之十六——状态模式

    一.状态模式的定义 状态模式的关键是区分事务内部和外部的状态,事务内部状态改变往往会带来事务的行为改变. 状态模式中有意思的一点是,一般我们谈到封装,都是优先封装对象的行为,而非对象的状态.但在状态模 ...

  4. 轻量级的jquery

    话不多说,直接上源代码 一.tool.js 封装一些共用方法,以及相关的浏览器兼容细节,供Base.js调用 //浏览器检测,一旦加载即执行 (function() { window.sys = {} ...

  5. NSTimer 线程操作

    http://www.jianshu.com/p/0c050af6c5ee 2.NSTimer的创建与撤销必须在同一个线程操作.performSelector的创建与撤销必须在同一个线程操作.

  6. 解决plsql工具不能用中文字进行模糊匹配

    今天碰到了 select * from table1 t where t.name like '模块a' 查不出数据 而select * from table1 t where t.name like ...

  7. Leetcode: Evaluate Division

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  8. application 统计网站访问人数

    参考书<JSP Web 开发案例教程> index.jsp welcome.jsp 显示

  9. TTabControl、TMemo组件(制作一个简单的多文本编辑框)

    TTabControl包含一列字符串标签的tabs 每个标签控制一个对象 首先创建一个TForm;接下来添加TTabControl组件和一个文件对话框TOpenDialog(用于添加文件),然后在TT ...

  10. 。。。无语的Eclipse+Tomact。。。

    晕哦,今天又被Eclipse给骗了,今天部署了一个SSH的环境,搞了半天,JAR包是通过BuildPath导入进去的,怎么搞都报错,说是找不到Spring-Web的一个Jar包,差点没有把我给弄死.. ...