微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Bootstrap整体框架之CSS12栅格系统

1.整体架构

BootStrap框架公共六个部分:(css组件和js插件是其表现形式,其余的是基础支撑平台)

表现形式 CSS组件 JS插件 基础支撑平台 CSS12栅格系统 基础布局组件 jQuery 响应式设计

1.1 CSS12栅格系统

12栅格系统是BootStrap的核心功能,也是响应式设计核心理念的一个实现方式。

1.1.1 实现原理

栅格布局原理:定义容器大小,平分12分,在调整内外边距,最后结合媒体查询,制作出强大响应式的栅格系统。

1.最外层的边框,伴随着响应式思想,区分了四种类型浏览器,像素分界点768px、992px、1200px 2.第二层的边框,即.container样式容器,针对四种浏览器宽度不一样,值是自动、750px、970px、1170px

rush:css;"> //源码 .container { padding-right: 15px; padding-left: 15px; margin-right: auto; margin-left: auto; } @media (min-width: 768px) { .container { width: 750px; } } @media (min-width: 992px) { .container { width: 970px; } } @media (min-width: 1200px) { .container { width: 1170px; } }

3.1号横条,左内边距和右内边距是15px,是12个col-lg-1,没有row,则会

rush:css;"> //源码 .col-xs-1,.col-sm-1,.col-md-1,.col-lg-1,.col-xs-2,.col-sm-2,.col-md-2,.col-lg-2,.col-xs-3,.col-sm-3,.col-md-3,.col-lg-3,.col-xs-4,.col-sm-4,.col-md-4,.col-lg-4,.col-xs-5,.col-sm-5,.col-md-5,.col-lg-5,.col-xs-6,.col-sm-6,.col-md-6,.col-lg-6,.col-xs-7,.col-sm-7,.col-md-7,.col-lg-7,.col-xs-8,.col-sm-8,.col-md-8,.col-lg-8,.col-xs-9,.col-sm-9,.col-md-9,.col-lg-9,.col-xs-10,.col-sm-10,.col-md-10,.col-lg-10,.col-xs-11,.col-sm-11,.col-md-11,.col-lg-11,.col-xs-12,.col-sm-12,.col-md-12,.col-lg-12 { position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px; }

<div class="jb51code">
<pre class="brush:xhtml;">
<!DOCTYPE html>
<html lang="en">

<Meta charset="utf-8"> <Meta http-equiv="X-UA-Compatible" content="IE=edge"> <Meta name="viewport" content="width=device-width,initial-scale=1">
<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->
<link href="bootstrap-3.3.7-<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>t/css/bootstrap.min.css" rel="stylesheet"&gt;

4.2号横条,也就是row容器的定义,margin-left和margin-right都是-15px,组合row和列后,形成3号横条的效果,也就是左右宽度用满的效果

rush:css;"> //源码 .row { margin-right: -15px; margin-left: -15px; }

有row,则会没边距

rush:xhtml;"> <Meta charset="utf-8"> <Meta http-equiv="X-UA-Compatible" content="IE=edge"> <Meta name="viewport" content="width=device-width,initial-scale=1">
<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->
<link href="bootstrap-3.3.7-<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>t/css/bootstrap.min.css" rel="stylesheet"&gt;

1.1.2 基本用法

1.列组合

rush:xhtml;">

实现很简单,就是涉及了两个CSS特性:左浮动和宽度百分比

rush:css;"> //源码 @media (min-width: 1200px) { .col-lg-1,.col-lg-12 { float: left; } .col-lg-12 { width: 100%; } .col-lg-11 { width: 91.66666667%; } .col-lg-10 { width: 83.33333333%; } .col-lg-9 { width: 75%; } .col-lg-8 { width: 66.66666667%; } .col-lg-7 { width: 58.33333333%; } .col-lg-6 { width: 50%; } .col-lg-5 { width: 41.66666667%; } .col-lg-4 { width: 33.33333333%; } .col-lg-3 { width: 25%; } .col-lg-2 { width: 16.66666667%; } .col-lg-1 { width: 8.33333333%; } }

2.列偏移

我们不想让相邻的列挨在一起,则利用栅格系统的列偏移.col-xs(sm,md,lg)-offset-* 功能来实现,不必再定义margin

rush:xhtml;">
rush:css;"> //源码 .col-lg-offset-12 { margin-left: 100%; } .col-lg-offset-11 { margin-left: 91.66666667%; } .col-lg-offset-10 { margin-left: 83.33333333%; } .col-lg-offset-9 { margin-left: 75%; } .col-lg-offset-8 { margin-left: 66.66666667%; } .col-lg-offset-7 { margin-left: 58.33333333%; } .col-lg-offset-6 { margin-left: 50%; } .col-lg-offset-5 { margin-left: 41.66666667%; } .col-lg-offset-4 { margin-left: 33.33333333%; } .col-lg-offset-3 { margin-left: 25%; } .col-lg-offset-2 { margin-left: 16.66666667%; } .col-lg-offset-1 { margin-left: 8.33333333%; } .col-lg-offset-0 { margin-left: 0; }

3.列嵌套

栅格系统也支持列嵌套,也就是一个列中可以在声明一个或者多个行.内部嵌套的row宽度是100%,就是当前外部列的宽度

rush:xhtml;">

4.列排序

列排序就是改变列的方向,也就是改变左右浮动,并且设置浮动的距离。可以通过.col-xs(sm,lg)-pull(push)-* 所有列设置的都是左浮动,通过设置left和right来实现定位显示。push则设置left,pull则设置right

其实只是利用了float,left,right三个属性就实现了这种效果

rush:css;"> //源码 .col-lg-pull-12 { right: 100%; } .col-lg-pull-11 { right: 91.66666667%; } .col-lg-pull-10 { right: 83.33333333%; } .col-lg-pull-9 { right: 75%; } .col-lg-pull-8 { right: 66.66666667%; } .col-lg-pull-7 { right: 58.33333333%; } .col-lg-pull-6 { right: 50%; } .col-lg-pull-5 { right: 41.66666667%; } .col-lg-pull-4 { right: 33.33333333%; } .col-lg-pull-3 { right: 25%; } .col-lg-pull-2 { right: 16.66666667%; } .col-lg-pull-1 { right: 8.33333333%; } .col-lg-pull-0 { right: auto; } .col-lg-push-12 { left: 100%; } .col-lg-push-11 { left: 91.66666667%; } .col-lg-push-10 { left: 83.33333333%; } .col-lg-push-9 { left: 75%; } .col-lg-push-8 { left: 66.66666667%; } .col-lg-push-7 { left: 58.33333333%; } .col-lg-push-6 { left: 50%; } .col-lg-push-5 { left: 41.66666667%; } .col-lg-push-4 { left: 33.33333333%; } .col-lg-push-3 { left: 25%; } .col-lg-push-2 { left: 16.66666667%; } .col-lg-push-1 { left: 8.33333333%; } .col-lg-push-0 { left: auto; }

1.1.3 响应式栅格

已知col-xs-* col-sm-* col-md-* col-lg-*

1.跨设备组合定义 一种样式(比如col-md-9)在其定义的尺寸范围以外是不起作用的,比如,在小型或者大型屏幕上,所有带有md的样式都不会生效。我们可以在一个元素上应用不同的样式,以适配不同尺寸的屏幕。

rush:xhtml;">

如图,由于div3换行时,但div1过高,则div3就右边紧挨着显示了。 所以需要利用clearfix样式清除浮动,但前提是在超小型屏幕上才显示(用visible-xs控制)

rush:xhtml;">

.btn-group:before,.btn-group-vertical > .btn-group:after,.nav:before,.nav:after,.navbar:before,.navbar:after,.navbar-header:before,.navbar-header:after,.navbar-collapse:before,.navbar-collapse:after,.pager:before,.pager:after,.panel-body:before,.panel-body:after,.modal-header:before,.modal-header:after,.modal-footer:before,.modal-footer:after { display: table; content: " "; } .clearfix:after,.modal-footer:after { clear: both; } //源代码 @media (max-width: 767px) { .visible-xs { display: block !important; } table.visible-xs { display: table !important; } tr.visible-xs { display: table-row !important; } th.visible-xs,td.visible-xs { display: table-cell !important; } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐