1-2 Bootstrap到底是什么?
本节编程练习不计算学习进度,请电脑登录imooc.com操作

Bootstrap到底是什么?

欢迎来到Bootstrap课堂,加入高端大气上档次的web前端开发团队。上一小节Bootstrap做了简单的介绍,下面我们再来了解一下Bootstrap的前世今缘,在右侧是用Bootstrap预设的组件样式,包括按钮、表格、标签、导航等,感兴趣的小伙伴可以先睹为快,后面的章节我们会对这些组件做详细讲解。

2011年,twitter的“一小撮”工程师为了提高他们内部的分析和管理能力,用业余时间为他们的产品构建了一套易用、优雅、灵活、可扩展的前端工具集--BootStrap。Bootstrap由MARK OTTO和Jacob Thornton所设计和建立,在github上开源之后,迅速成为该站上最多人watch&fork的项目。大量工程师踊跃为该项目贡献代码,社区惊人地活跃,代码版本进化非常快速,官方文档质量极其高(可以说是优雅),同时涌现了许多基于Bootstrap建设的网站:界面清新、简洁;要素排版利落大方。如屏幕这几个网站页面都是用Bootstrap框架制作的:

(http://www.ghostchina.com/)

(http://www.zend.com/)

(http://www.uberflip.com/)

GitHub上这样介绍 bootstrap:

    ☑  简单灵活可用于架构流行的用户界面和交互接口的html、css、javascript工具集。

    ☑  基于html5、css3的bootstrap,具有大量的诱人特性:友好的学习曲线,卓越的兼容性,响应式设计,12列格网,样式向导文档。

    ☑  自定义JQuery插件,完整的类库,基于Less等。

Bootstrap是否真的非常实用?带着这些问题,我们将完成接下来的学习旅程——玩转Bootstrap,并且通过Bootstrap构建自己的Web应用程序或者Web网站。

此课Bootstrap下载等更多信息详见WIKI。

任务

我来试试:观察代码编辑器中的代码,体验一下Booststrap对样式的各种使用。
 

  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <title>Theme Template for Bootstrap</title>
  6. <!-- Bootstrap core CSS -->
  7. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  8. </head>
  9. <body role="document">
  10. <div class="container theme-showcase" role="main">
  11. <!-- Main jumbotron for a primary marketing message or call to action -->
  12. <div class="jumbotron">
  13. <h1>Hello, world!</h1>
  14. <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
  15. <p><a href="#" class="btn btn-primary btn-lg" role="button">Learn more »</a></p>
  16. </div>
  17.  
  18. <div class="page-header">
  19. <h1>按钮</h1>
  20. </div>
  21. <p>
  22. <button type="button" class="btn btn-lg btn-default">Default</button>
  23. <button type="button" class="btn btn-lg btn-primary">Primary</button>
  24. <button type="button" class="btn btn-lg btn-success">Success</button>
  25. <button type="button" class="btn btn-lg btn-info">Info</button>
  26. <button type="button" class="btn btn-lg btn-warning">Warning</button>
  27. <button type="button" class="btn btn-lg btn-danger">Danger</button>
  28. <button type="button" class="btn btn-lg btn-link">Link</button>
  29. </p>
  30. <p>
  31. <button type="button" class="btn btn-default">Default</button>
  32. <button type="button" class="btn btn-primary">Primary</button>
  33. <button type="button" class="btn btn-success">Success</button>
  34. <button type="button" class="btn btn-info">Info</button>
  35. <button type="button" class="btn btn-warning">Warning</button>
  36. <button type="button" class="btn btn-danger">Danger</button>
  37. <button type="button" class="btn btn-link">Link</button>
  38. </p>
  39. <p>
  40. <button type="button" class="btn btn-sm btn-default">Default</button>
  41. <button type="button" class="btn btn-sm btn-primary">Primary</button>
  42. <button type="button" class="btn btn-sm btn-success">Success</button>
  43. <button type="button" class="btn btn-sm btn-info">Info</button>
  44. <button type="button" class="btn btn-sm btn-warning">Warning</button>
  45. <button type="button" class="btn btn-sm btn-danger">Danger</button>
  46. <button type="button" class="btn btn-sm btn-link">Link</button>
  47. </p>
  48. <p>
  49. <button type="button" class="btn btn-xs btn-default">Default</button>
  50. <button type="button" class="btn btn-xs btn-primary">Primary</button>
  51. <button type="button" class="btn btn-xs btn-success">Success</button>
  52. <button type="button" class="btn btn-xs btn-info">Info</button>
  53. <button type="button" class="btn btn-xs btn-warning">Warning</button>
  54. <button type="button" class="btn btn-xs btn-danger">Danger</button>
  55. <button type="button" class="btn btn-xs btn-link">Link</button>
  56. </p>
  57. <div class="page-header">
  58. <h1>表格</h1>
  59. </div>
  60. <div class="row">
  61. <div class="col-md-6">
  62. <table class="table">
  63. <thead>
  64. <tr>
  65. <th>#</th>
  66. <th>First Name</th>
  67. <th>Last Name</th>
  68. <th>Username</th>
  69. </tr>
  70. </thead>
  71. <tbody>
  72. <tr>
  73. <td>1</td>
  74. <td>Mark</td>
  75. <td>Otto</td>
  76. <td>@mdo</td>
  77. </tr>
  78. <tr>
  79. <td>2</td>
  80. <td>Jacob</td>
  81. <td>Thornton</td>
  82. <td>@fat</td>
  83. </tr>
  84. <tr>
  85. <td>3</td>
  86. <td>Larry</td>
  87. <td>the Bird</td>
  88. <td>@twitter</td>
  89. </tr>
  90. </tbody>
  91. </table>
  92. </div>
  93. <div class="col-md-6">
  94. <table class="table table-striped">
  95. <thead>
  96. <tr>
  97. <th>#</th>
  98. <th>First Name</th>
  99. <th>Last Name</th>
  100. <th>Username</th>
  101. </tr>
  102. </thead>
  103. <tbody>
  104. <tr>
  105. <td>1</td>
  106. <td>Mark</td>
  107. <td>Otto</td>
  108. <td>@mdo</td>
  109. </tr>
  110. <tr>
  111. <td>2</td>
  112. <td>Jacob</td>
  113. <td>Thornton</td>
  114. <td>@fat</td>
  115. </tr>
  116. <tr>
  117. <td>3</td>
  118. <td>Larry</td>
  119. <td>the Bird</td>
  120. <td>@twitter</td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. </div>
  125. </div>
  126. <div class="row">
  127. <div class="col-md-6">
  128. <table class="table table-bordered">
  129. <thead>
  130. <tr>
  131. <th>#</th>
  132. <th>First Name</th>
  133. <th>Last Name</th>
  134. <th>Username</th>
  135. </tr>
  136. </thead>
  137. <tbody>
  138. <tr>
  139. <td rowspan="2">1</td>
  140. <td>Mark</td>
  141. <td>Otto</td>
  142. <td>@mdo</td>
  143. </tr>
  144. <tr>
  145. <td>Mark</td>
  146. <td>Otto</td>
  147. <td>@TwBootstrap</td>
  148. </tr>
  149. <tr>
  150. <td>2</td>
  151. <td>Jacob</td>
  152. <td>Thornton</td>
  153. <td>@fat</td>
  154. </tr>
  155. <tr>
  156. <td>3</td>
  157. <td colspan="2">Larry the Bird</td>
  158. <td>@twitter</td>
  159. </tr>
  160. </tbody>
  161. </table>
  162. </div>
  163. <div class="col-md-6">
  164. <table class="table table-condensed">
  165. <thead>
  166. <tr>
  167. <th>#</th>
  168. <th>First Name</th>
  169. <th>Last Name</th>
  170. <th>Username</th>
  171. </tr>
  172. </thead>
  173. <tbody>
  174. <tr>
  175. <td>1</td>
  176. <td>Mark</td>
  177. <td>Otto</td>
  178. <td>@mdo</td>
  179. </tr>
  180. <tr>
  181. <td>2</td>
  182. <td>Jacob</td>
  183. <td>Thornton</td>
  184. <td>@fat</td>
  185. </tr>
  186. <tr>
  187. <td>3</td>
  188. <td colspan="2">Larry the Bird</td>
  189. <td>@twitter</td>
  190. </tr>
  191. </tbody>
  192. </table>
  193. </div>
  194. </div>
  195. <div class="page-header">
  196. <h1>Thumbnails</h1>
  197. </div>
  198. <img data-src="holder.js/200x200" class="img-thumbnail" alt="200x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgZmlsbD0iI2VlZSIvPjx0ZXh0IHRleHQtYW5jaG9yPSJtaWRkbGUiIHg9IjEwMCIgeT0iMTAwIiBzdHlsZT0iZmlsbDojYWFhO2ZvbnQtd2VpZ2h0OmJvbGQ7Zm9udC1zaXplOjEzcHg7Zm9udC1mYW1pbHk6QXJpYWwsSGVsdmV0aWNhLHNhbnMtc2VyaWY7ZG9taW5hbnQtYmFzZWxpbmU6Y2VudHJhbCI+MjAweDIwMDwvdGV4dD48L3N2Zz4=" style="width: 200px; height: 200px;">
  199. <div class="page-header">
  200. <h1>Labels</h1>
  201. </div>
  202. <h1>
  203. <span class="label label-default">Default</span>
  204. <span class="label label-primary">Primary</span>
  205. <span class="label label-success">Success</span>
  206. <span class="label label-info">Info</span>
  207. <span class="label label-warning">Warning</span>
  208. <span class="label label-danger">Danger</span>
  209. </h1>
  210. <h2>
  211. <span class="label label-default">Default</span>
  212. <span class="label label-primary">Primary</span>
  213. <span class="label label-success">Success</span>
  214. <span class="label label-info">Info</span>
  215. <span class="label label-warning">Warning</span>
  216. <span class="label label-danger">Danger</span>
  217. </h2>
  218. <h3>
  219. <span class="label label-default">Default</span>
  220. <span class="label label-primary">Primary</span>
  221. <span class="label label-success">Success</span>
  222. <span class="label label-info">Info</span>
  223. <span class="label label-warning">Warning</span>
  224. <span class="label label-danger">Danger</span>
  225. </h3>
  226. <h4>
  227. <span class="label label-default">Default</span>
  228. <span class="label label-primary">Primary</span>
  229. <span class="label label-success">Success</span>
  230. <span class="label label-info">Info</span>
  231. <span class="label label-warning">Warning</span>
  232. <span class="label label-danger">Danger</span>
  233. </h4>
  234. <h5>
  235. <span class="label label-default">Default</span>
  236. <span class="label label-primary">Primary</span>
  237. <span class="label label-success">Success</span>
  238. <span class="label label-info">Info</span>
  239. <span class="label label-warning">Warning</span>
  240. <span class="label label-danger">Danger</span>
  241. </h5>
  242. <h6>
  243. <span class="label label-default">Default</span>
  244. <span class="label label-primary">Primary</span>
  245. <span class="label label-success">Success</span>
  246. <span class="label label-info">Info</span>
  247. <span class="label label-warning">Warning</span>
  248. <span class="label label-danger">Danger</span>
  249. </h6>
  250. <p>
  251. <span class="label label-default">Default</span>
  252. <span class="label label-primary">Primary</span>
  253. <span class="label label-success">Success</span>
  254. <span class="label label-info">Info</span>
  255. <span class="label label-warning">Warning</span>
  256. <span class="label label-danger">Danger</span>
  257. </p>
  258. <div class="page-header">
  259. <h1>Badges</h1>
  260. </div>
  261. <p>
  262. <a href="#">Inbox <span class="badge">42</span></a>
  263. </p>
  264. <ul class="nav nav-pills" role="tablist">
  265. <li role="presentation" class="active"><a href="#">Home <span class="badge">42</span></a></li>
  266. <li role="presentation"><a href="#">Profile</a></li>
  267. <li role="presentation"><a href="#">Messages <span class="badge">3</span></a></li>
  268. </ul>
  269. <div class="page-header">
  270. <h1>Navs</h1>
  271. </div>
  272. <ul class="nav nav-tabs" role="tablist">
  273. <li role="presentation" class="active"><a href="#">Home</a></li>
  274. <li role="presentation"><a href="#">Profile</a></li>
  275. <li role="presentation"><a href="#">Messages</a></li>
  276. </ul>
  277. <ul class="nav nav-pills" role="tablist">
  278. <li role="presentation" class="active"><a href="#">Home</a></li>
  279. <li role="presentation"><a href="#">Profile</a></li>
  280. <li role="presentation"><a href="#">Messages</a></li>
  281. </ul>
  282. <div class="page-header">
  283. <h1>Navbars</h1>
  284. </div>
  285. <div class="navbar navbar-default">
  286. <div class="container">
  287. <div class="navbar-header">
  288. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
  289. <span class="sr-only">Toggle navigation</span>
  290. <span class="icon-bar"></span>
  291. <span class="icon-bar"></span>
  292. <span class="icon-bar"></span>
  293. </button>
  294. <a class="navbar-brand" href="#">Project name</a>
  295. </div>
  296. <div class="navbar-collapse collapse">
  297. <ul class="nav navbar-nav">
  298. <li class="active"><a href="#">Home</a></li>
  299. <li><a href="#about">About</a></li>
  300. <li><a href="#contact">Contact</a></li>
  301. <li class="dropdown">
  302. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
  303. <ul class="dropdown-menu" role="menu">
  304. <li><a href="#">Action</a></li>
  305. <li><a href="#">Another action</a></li>
  306. <li><a href="#">Something else here</a></li>
  307. <li class="divider"></li>
  308. <li class="dropdown-header">Nav header</li>
  309. <li><a href="#">Separated link</a></li>
  310. <li><a href="#">One more separated link</a></li>
  311. </ul>
  312. </li>
  313. </ul>
  314. </div><!--/.nav-collapse -->
  315. </div>
  316. </div>
  317. <div class="navbar navbar-inverse">
  318. <div class="container">
  319. <div class="navbar-header">
  320. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
  321. <span class="sr-only">Toggle navigation</span>
  322. <span class="icon-bar"></span>
  323. <span class="icon-bar"></span>
  324. <span class="icon-bar"></span>
  325. </button>
  326. <a class="navbar-brand" href="#">Project name</a>
  327. </div>
  328. <div class="navbar-collapse collapse">
  329. <ul class="nav navbar-nav">
  330. <li class="active"><a href="#">Home</a></li>
  331. <li><a href="#about">About</a></li>
  332. <li><a href="#contact">Contact</a></li>
  333. <li class="dropdown">
  334. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
  335. <ul class="dropdown-menu" role="menu">
  336. <li><a href="#">Action</a></li>
  337. <li><a href="#">Another action</a></li>
  338. <li><a href="#">Something else here</a></li>
  339. <li class="divider"></li>
  340. <li class="dropdown-header">Nav header</li>
  341. <li><a href="#">Separated link</a></li>
  342. <li><a href="#">One more separated link</a></li>
  343. </ul>
  344. </li>
  345. </ul>
  346. </div><!--/.nav-collapse -->
  347. </div>
  348. </div>
  349. <div class="page-header">
  350. <h1>Alerts</h1>
  351. </div>
  352. <div class="alert alert-success" role="alert">
  353. <strong>Well done!</strong> You successfully read this important alert message.
  354. </div>
  355. <div class="alert alert-info" role="alert">
  356. <strong>Heads up!</strong> This alert needs your attention, but it's not super important.
  357. </div>
  358. <div class="alert alert-warning" role="alert">
  359. <strong>Warning!</strong> Best check yo self, you're not looking too good.
  360. </div>
  361. <div class="alert alert-danger" role="alert">
  362. <strong>Oh snap!</strong> Change a few things up and try submitting again.
  363. </div>
  364. <div class="page-header">
  365. <h1>Progress bars</h1>
  366. </div>
  367. <div class="progress">
  368. <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"><span class="sr-only">60% Complete</span></div>
  369. </div>
  370. <div class="progress">
  371. <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%"><span class="sr-only">40% Complete (success)</span></div>
  372. </div>
  373. <div class="progress">
  374. <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%"><span class="sr-only">20% Complete</span></div>
  375. </div>
  376. <div class="progress">
  377. <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%"><span class="sr-only">60% Complete (warning)</span></div>
  378. </div>
  379. <div class="progress">
  380. <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%"><span class="sr-only">80% Complete (danger)</span></div>
  381. </div>
  382. <div class="progress">
  383. <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%"><span class="sr-only">60% Complete</span></div>
  384. </div>
  385. <div class="progress">
  386. <div class="progress-bar progress-bar-success" style="width: 35%"><span class="sr-only">35% Complete (success)</span></div>
  387. <div class="progress-bar progress-bar-warning" style="width: 20%"><span class="sr-only">20% Complete (warning)</span></div>
  388. <div class="progress-bar progress-bar-danger" style="width: 10%"><span class="sr-only">10% Complete (danger)</span></div>
  389. </div>
  390. <div class="page-header">
  391. <h1>List groups</h1>
  392. </div>
  393. <div class="row">
  394. <div class="col-sm-4">
  395. <ul class="list-group">
  396. <li class="list-group-item">Cras justo odio</li>
  397. <li class="list-group-item">Dapibus ac facilisis in</li>
  398. <li class="list-group-item">Morbi leo risus</li>
  399. <li class="list-group-item">Porta ac consectetur ac</li>
  400. <li class="list-group-item">Vestibulum at eros</li>
  401. </ul>
  402. </div><!-- /.col-sm-4 -->
  403. <div class="col-sm-4">
  404. <div class="list-group">
  405. <a href="#" class="list-group-item active">
  406. Cras justo odio
  407. </a>
  408. <a href="#" class="list-group-item">Dapibus ac facilisis in</a>
  409. <a href="#" class="list-group-item">Morbi leo risus</a>
  410. <a href="#" class="list-group-item">Porta ac consectetur ac</a>
  411. <a href="#" class="list-group-item">Vestibulum at eros</a>
  412. </div>
  413. </div><!-- /.col-sm-4 -->
  414. <div class="col-sm-4">
  415. <div class="list-group">
  416. <a href="#" class="list-group-item active">
  417. <h4 class="list-group-item-heading">List group item heading</h4>
  418. <p class="list-group-item-text">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
  419. </a>
  420. <a href="#" class="list-group-item">
  421. <h4 class="list-group-item-heading">List group item heading</h4>
  422. <p class="list-group-item-text">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
  423. </a>
  424. <a href="#" class="list-group-item">
  425. <h4 class="list-group-item-heading">List group item heading</h4>
  426. <p class="list-group-item-text">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
  427. </a>
  428. </div>
  429. </div><!-- /.col-sm-4 -->
  430. </div>
  431. <div class="page-header">
  432. <h1>Panels</h1>
  433. </div>
  434. <div class="row">
  435. <div class="col-sm-4">
  436. <div class="panel panel-default">
  437. <div class="panel-heading">
  438. <h3 class="panel-title">Panel title</h3>
  439. </div>
  440. <div class="panel-body">
  441. Panel content
  442. </div>
  443. </div>
  444. <div class="panel panel-primary">
  445. <div class="panel-heading">
  446. <h3 class="panel-title">Panel title</h3>
  447. </div>
  448. <div class="panel-body">
  449. Panel content
  450. </div>
  451. </div>
  452. </div><!-- /.col-sm-4 -->
  453. <div class="col-sm-4">
  454. <div class="panel panel-success">
  455. <div class="panel-heading">
  456. <h3 class="panel-title">Panel title</h3>
  457. </div>
  458. <div class="panel-body">
  459. Panel content
  460. </div>
  461. </div>
  462. <div class="panel panel-info">
  463. <div class="panel-heading">
  464. <h3 class="panel-title">Panel title</h3>
  465. </div>
  466. <div class="panel-body">
  467. Panel content
  468. </div>
  469. </div>
  470. </div><!-- /.col-sm-4 -->
  471. <div class="col-sm-4">
  472. <div class="panel panel-warning">
  473. <div class="panel-heading">
  474. <h3 class="panel-title">Panel title</h3>
  475. </div>
  476. <div class="panel-body">
  477. Panel content
  478. </div>
  479. </div>
  480. <div class="panel panel-danger">
  481. <div class="panel-heading">
  482. <h3 class="panel-title">Panel title</h3>
  483. </div>
  484. <div class="panel-body">
  485. Panel content
  486. </div>
  487. </div>
  488. </div><!-- /.col-sm-4 -->
  489. </div>
  490. </div> <!-- /container -->
  491. <!-- Bootstrap core JavaScript
  492. ================================================== -->
  493. <!-- Placed at the end of the document so the pages load faster -->
  494. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  495. </body>
  496. </html>
下一节