热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

[转载]UnderstandingtheBootstrap3GridSystem

https:scotch.iotutorialsunderstanding-the-bootstrap-3-grid-systemWiththe3rdversionofthegre

https://scotch.io/tutorials/understanding-the-bootstrap-3-grid-system

With the 3rd version of the great Bootstrap out for about 4 and a half months now, people have had their time to play around with it, learn the changes, find new features, and build amazing things.

The Difference

The most interesting change for me was the difference in the grid system. Bootstrap 2 catered to two different browser sizes (desktop and then mobile). With Bootstrap 3, you now build with mobile in mind first, and the grid system lets you create different grid systems based on browser size.

Bootstrap 2

The grid you create works on desktops and then stacks on top of each other when browser size is below 767px. This is limited since you can only define 1 grid on desktop sized browsers. You are left with a stacked grid on mobile devices.

Bootstrap 3

The new Bootstrap grid system applies to mobile first. When you declare a specific grid size, that is the grid for that size and above. This can be a little hard to grasp at first so here’s an example.

For example, let’s say you want a site that has:


  • 1 column on extra small devices

  • 2 columns on small AND medium devices

  • 4 columns on large devices

Since the grid system now cascades up from mobile devices, this is how this code will look.


class="row">
class="col-sm-6 col-lg-3">
This is part of our grid.
>
class="col-sm-6 col-lg-3">
This is part of our grid.
>
class="col-sm-6 col-lg-3">
This is part of our grid.
>
class="col-sm-6 col-lg-3">
This is part of our grid.
>
>

We don’t have to define anything for extra small devices since the default is one column. We have to define a grid size for small devices, but not for medium devices. This is because the grid cascades up. So if you define a size at sm, then it will be that grid size for sm, md, and lg.

We’ll explain the different grid sizes and how you create them and then show examples.

The Grid Sizes

This is the best part about the new grid system. You could realistically have your site show a different grid on 4 different browser sizes. Below is the breakdown of the different sizes.

























.col-xs-$Extra SmallPhones Less than 768px
.col-sm-$Small DevicesTablets 768px and Up
.col-md-$Medium DevicesDesktops 992px and Up
.col-lg-$Large DevicesLarge Desktops 1200px and Up

The official Bootstrap docs offer a much more comprehensive understanding of how the grid works. Take a look at those to get a more solid overview of column sizes, gutter sizes, maximum column sizes, and the max-width of your overall site based on browser size.

Default Sizes for the Bootstrap Grid

Sometimes you will need to use media queries to get your site to act the way you’d like it to. Knowing the default grid sizes is essential to extending the Bootstrap grid. We’ve written up a quick tip to show you the default sizes so take a look if you need the Bootstrap media queries and breakpoints.

Responsive Utilities

Just like Bootstrap 2, Bootstrap 3 provides responsive utilities for hiding and showing elements based on the browser size. This will also help us in defining our grid system.


  • .visible-xs

  • .visible-sm

  • .visible-md

  • .visible-lg

  • .hidden-xs

  • .hidden-sm

  • .hidden-md

  • .hidden-lg

This helps because we are able to show certain elements based on size. In our examples today, we’ll be showing an extra sidebar on large desktops.

Examples

Here are a few examples of the grids that you can create. We’ll go through some basic sites that some people might want and show how easy it is to build that site with the Bootstrap 3 grid.

Resize your browser’s width to see the different grids in action.

Simple: Large Desktop vs Mobile

Let’s say you wanted a site to have 1 column on extra small (phone) and small (tablet) devices, 2 columns on medium (medium desktop) devices, and 4 columns on large (desktop) devices.



Large Devices!



Large Devices!



Large Devices!



Large Devices!


Here is the code for that example:


class="row">
class="col-md-6 col-lg-3">
class="visible-lg text-success">Large Devices!>
class="visible-md text-warning">Medium Devices!>
class="visible-xs visible-sm text-danger">Extra Small and Small Devices>
>
class="col-md-6 col-lg-3">
class="visible-lg text-success">Large Devices!>
class="visible-md text-warning">Medium Devices!>
class="visible-xs visible-sm text-danger">Extra Small and Small Devices>
>
class="col-md-6 col-lg-3">
class="visible-lg text-success">Large Devices!>
class="visible-md text-warning">Medium Devices!>
class="visible-xs visible-sm text-danger">Extra Small and Small Devices>
>
class="col-md-6 col-lg-3">
class="visible-lg text-success">Large Devices!>
class="visible-md text-warning">Medium Devices!

Extra Small and Small Devices





Intermediate: Show Extra Column on Large Desktops

This is an interesting example and one that the new grid excels at. Let’s say you have a site that has a sidebar and a main content section. For extra small devices, you want one column, main content with the sidebar stacked below it. For small and medium devices, we want sidebar and main content to sit side by side. Now for large devices, we want to utilize the space on larger devices. We want to add an extra sidebar to show more content.



I am the main content.



I am the main sidebar.



I am the secondary sidebar that only shows up on LARGE devices.


We change the size of the main content to span 6 columns on large devices to make room for our second sidebar. This is a great way to utilize the space on larger desktops. And here is the code for that example.


class="row">
class="col-sm-9 col-lg-6 text-danger">
I am the main content.
>
class="col-sm-3 text-warning">
I am the main sidebar.
>
class="col-lg-3 visible-lg text-success">
I am the secondary sidebar that only shows up on LARGE devices.
>
>


Advanced: Different Grid For Every Size

This will be a more complex example. Let’s say that at no point in our grid system do we want all of our columns to stack. For extra small devices, we want 2 columns. For small devices, we want 3 columns. For medium devices, we want 4 columns. For large devices, we want 6 columns (one that only shows on large devices).

You get the drill now. Let’s just straight into the example and code.



I’m content!



I’m content!



I’m content!



I’m content!



I’m content!



I’m content only visible on large devices!



class="row">
class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
I‘m content!
>
class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
I‘m content!
>
class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
I‘m content!
>
class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
I‘m content!
>
class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
I‘m content!
>
class="col-xs-6 col-sm-4 col-md-3 col-lg-2 visible-lg">
I‘m content only visible on large devices!
>
>

You can see that as the browser size gets smaller, the columns start to form. Also, the content inside each will begin stacking.

It’s Gridtastic!

You can see how easily it is to build complex and dynamic sites with the Bootstrap 3 grid. From mobile 2 column sites to complex hiding and showing elements on large desktops, you can build any type of site. Hopefully these examples will give you an idea of the flexibility of the new grid system and all the great things you can create.


推荐阅读
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • CentOS 7部署KVM虚拟化环境之一架构介绍
    本文介绍了CentOS 7部署KVM虚拟化环境的架构,详细解释了虚拟化技术的概念和原理,包括全虚拟化和半虚拟化。同时介绍了虚拟机的概念和虚拟化软件的作用。 ... [详细]
author-avatar
woainimamamamama
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有