bootstrap的常用组件和栅格式布局详解


Posted in Javascript onMay 02, 2017

Bootstrap 是最受欢迎的 HTML、CSS 和 JS 框架,用于开发响应式布局、移动设备优先的 WEB 项目。

因为Bootstrap需要jquery的支持,所以在使用Bootstrap之前要先把jquery插件导入,并且要把bootstrap.js文件放在jquery.js之后改动方可生效。

Bootstrap中有许多好用的组件,只要以规定的class等命名就可以轻松使用这些插件。例如:

导航条:

<nav class="navbar navbar-default">
 <div class="container-fluid">
  <!-- Brand and toggle get grouped for better mobile display -->
  <div class="navbar-header">
   <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
   </button>
   <a class="navbar-brand" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Brand</a>
  </div>

  <!-- Collect the nav links, forms, and other content for toggling -->
  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
   <ul class="nav navbar-nav">
    <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link <span class="sr-only">(current)</span></a></li>
    <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link</a></li>
    <li class="dropdown">
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
     <ul class="dropdown-menu">
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Action</a></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Another action</a></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Something else here</a></li>
      <li role="separator" class="divider"></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Separated link</a></li>
      <li role="separator" class="divider"></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >One more separated link</a></li>
     </ul>
    </li>
   </ul>
   <form class="navbar-form navbar-left">
    <div class="form-group">
     <input type="text" class="form-control" placeholder="Search">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
   </form>
   <ul class="nav navbar-nav navbar-right">
    <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Link</a></li>
    <li class="dropdown">
     <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
     <ul class="dropdown-menu">
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Action</a></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Another action</a></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Something else here</a></li>
      <li role="separator" class="divider"></li>
      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Separated link</a></li>
     </ul>
    </li>
   </ul>
  </div><!-- /.navbar-collapse -->
 </div><!-- /.container-fluid -->
</nav>

以上述的格式写出需要的代码就可以获得以下样式的导航条:

bootstrap的常用组件和栅格式布局详解

注:在上述代码中form表单即serch和submit部位,带有class="dropdown"的就是下拉菜单的区域,class="dropdown-menu"的就是下拉菜单的内容区,这些部分并非主要内容,可以删除。通过class="navbar-right/left/"可以设置该部位的导航条在总区域的左侧还是右侧。

栅格系统:

栅格系统是bootstrap中最为重要的部分,它通过

<div class="row">
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
 <div class="col-md-1">.col-md-1</div>
</div>
<div class="row">
 <div class="col-md-8">.col-md-8</div>
 <div class="col-md-4">.col-md-4</div>
</div>
<div class="row">
 <div class="col-md-4">.col-md-4</div>
 <div class="col-md-4">.col-md-4</div>
 <div class="col-md-4">.col-md-4</div>
</div>
<div class="row">
 <div class="col-md-6">.col-md-6</div>
 <div class="col-md-6">.col-md-6</div>
</div>

这样的形式来实现网页布局,只要调节class="col-md-6"就可以轻松改变单元格区域的排布,

如图:

bootstrap的常用组件和栅格式布局详解

注:

bootstrap的常用组件和栅格式布局详解

如上表:由于bootstrap是移动优先的,所以在判定时先从小屏开始,如col-xs-6指的是从width=768开始直到最大都是占6个单位的空间。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
JavaScript-世界上误解最深的语言分析
Aug 12 Javascript
利用js获取服务器时间的两个简单方法
Jan 08 Javascript
最佳JS代码编写的14条技巧
Jan 09 Javascript
防止按钮在短时间内被多次点击的方法
Mar 10 Javascript
JavaScript驾驭网页-获取网页元素
Mar 24 Javascript
详解Angular的数据显示优化处理
Dec 26 Javascript
Three.js获取鼠标点击的三维坐标示例代码
Mar 24 Javascript
jQuery插件FusionCharts绘制的2D条状图效果【附demo源码】
May 13 jQuery
关于JavaScript语句后面的分号问题
Dec 07 Javascript
在微信小程序中使用图表的方法示例
Apr 25 Javascript
微信小程序和百度的语音识别接口详解
May 06 Javascript
JavaScript实现简易聊天对话框(加滚动条)
Feb 10 Javascript
Vuejs实现带样式的单文件组件新方法
May 02 #Javascript
基于bootstrap实现bootstrap中文网巨幕效果
May 02 #Javascript
老生常谈js-react组件生命周期
May 02 #Javascript
js 用于检测类数组对象的函数方法
May 02 #Javascript
使用Bootstrap打造特色进度条效果
May 02 #Javascript
在百度搜索结果中去除掉一些网站的资料(通过js控制不让显示)
May 02 #Javascript
js实现字符全排列算法的简单方法
May 01 #Javascript
You might like
对javascript和select部件的结合运用
2006/10/09 PHP
PHP 已经成熟
2006/12/04 PHP
php设计模式 Visitor 访问者模式
2011/06/28 PHP
PHP gbk环境下json_dencode传送来的汉字
2012/11/13 PHP
PHP中读取文件的几个方法总结(推荐)
2016/06/03 PHP
PHP 文件锁与进程锁的使用示例
2017/08/07 PHP
tp5 sum某个字段相加得到总数的例子
2019/10/18 PHP
关于Laravel参数验证的一些疑与惑
2019/11/19 PHP
JS中style属性
2006/10/11 Javascript
JavaScript实现Sleep函数的代码
2007/03/04 Javascript
利用javascript实现一些常用软件的下载导航
2009/08/03 Javascript
jQuery插件zepto.js简单实现tab切换
2015/06/16 Javascript
javascript实现的多个层切换效果通用函数实例
2015/07/06 Javascript
javascript顺序加载图片的方法
2015/07/18 Javascript
高性能JavaScript DOM编程(1)
2015/08/11 Javascript
网页挂马方式整理及详细介绍
2016/11/03 Javascript
vue路由中前进后退的一些事儿
2019/05/18 Javascript
Nodejs libuv运行原理详解
2019/08/21 NodeJs
VUE 组件转换为微信小程序组件的方法
2019/11/06 Javascript
BootStrap前端框架使用方法详解
2020/02/26 Javascript
复习Python中的字符串知识点
2015/04/14 Python
详细解析Python中__init__()方法的高级应用
2015/05/11 Python
python实现爬虫统计学校BBS男女比例(一)
2015/12/31 Python
Python的Django中将文件上传至七牛云存储的代码分享
2016/06/03 Python
python 将md5转为16字节的方法
2018/05/29 Python
Python字符串通过'+'和join函数拼接新字符串的性能测试比较
2019/03/05 Python
Python K最近邻从原理到实现的方法
2019/08/15 Python
python实现输出一个序列的所有子序列示例
2019/11/18 Python
Django xadmin安装及使用详解
2020/10/26 Python
Jack Rogers官网:美国经典的女性鞋靴品牌
2019/09/04 全球购物
加拿大服装和鞋类零售商:Mark’s
2021/01/04 全球购物
经济管理毕业生求职信
2014/03/15 职场文书
社区居务公开实施方案
2014/03/27 职场文书
《赶海》教学反思
2014/04/20 职场文书
2016大一新生军训心得体会
2016/01/11 职场文书
matplotlib之pyplot模块实现添加子图subplot的使用
2021/04/25 Python