热门标签 | 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.


推荐阅读
  • Python 伦理黑客技术:深入探讨后门攻击(第三部分)
    在《Python 伦理黑客技术:深入探讨后门攻击(第三部分)》中,作者详细分析了后门攻击中的Socket问题。由于TCP协议基于流,难以确定消息批次的结束点,这给后门攻击的实现带来了挑战。为了解决这一问题,文章提出了一系列有效的技术方案,包括使用特定的分隔符和长度前缀,以确保数据包的准确传输和解析。这些方法不仅提高了攻击的隐蔽性和可靠性,还为安全研究人员提供了宝贵的参考。 ... [详细]
  • Ext JS MVC系列一:环境搭建与框架概览
    本文主要介绍了如何在项目中使用Ext JS 4作为前端框架,并详细讲解了Ext JS 4的MVC开发模式。文章将从项目目录结构、相关CSS和JS文件的引用以及MVC框架的整体认识三个方面进行总结。 ... [详细]
  • 解决Bootstrap DataTable Ajax请求重复问题
    在最近的一个项目中,我们使用了JQuery DataTable进行数据展示,虽然使用起来非常方便,但在测试过程中发现了一个问题:当查询条件改变时,有时查询结果的数据不正确。通过FireBug调试发现,点击搜索按钮时,会发送两次Ajax请求,一次是原条件的请求,一次是新条件的请求。 ... [详细]
  • 第二十五天接口、多态
    1.java是面向对象的语言。设计模式:接口接口类是从java里衍生出来的,不是python原生支持的主要用于继承里多继承抽象类是python原生支持的主要用于继承里的单继承但是接 ... [详细]
  • 解决Parallels Desktop错误15265的方法
    本文详细介绍了在使用Parallels Desktop时遇到错误15265的多种解决方案,包括检查网络连接、关闭代理服务器和修改主机文件等步骤。 ... [详细]
  • 解决 Windows Server 2016 网络连接问题
    本文详细介绍了如何解决 Windows Server 2016 在使用无线网络 (WLAN) 和有线网络 (以太网) 时遇到的连接问题。包括添加必要的功能和安装正确的驱动程序。 ... [详细]
  • 在使用Eclipse进行调试时,如果遇到未解析的断点(unresolved breakpoint)并显示“未加载符号表,请使用‘file’命令加载目标文件以进行调试”的错误提示,这通常是因为调试器未能正确加载符号表。解决此问题的方法是通过GDB的`file`命令手动加载目标文件,以便调试器能够识别和解析断点。具体操作为在GDB命令行中输入 `(gdb) file `。这一步骤确保了调试环境能够正确访问和解析程序中的符号信息,从而实现有效的调试。 ... [详细]
  • 在 LeetCode 的“有效回文串 II”问题中,给定一个非空字符串 `s`,允许删除最多一个字符。本篇深入解析了如何判断删除一个字符后,字符串是否能成为回文串,并提出了高效的优化算法。通过详细的分析和代码实现,本文提供了多种解决方案,帮助读者更好地理解和应用这一算法。 ... [详细]
  • 本文详细解析了Autofac在高级应用场景中的具体实现,特别是如何通过注册泛型接口的类来优化依赖注入。示例代码展示了如何使用 `builder.RegisterAssemblyTypes` 方法,结合 `typeof(IEventHandler).Assembly` 和 `Where` 过滤条件,动态注册所有符合条件的类,从而简化配置并提高代码的可维护性。此外,文章还探讨了这一方法在复杂系统中的实际应用及其优势。 ... [详细]
  • [c++基础]STL
    cppfig15_10.cppincludeincludeusingnamespacestd;templatevoidprintVector(constvector&integer ... [详细]
  • 开机自启动的几种方式
    0x01快速自启动目录快速启动目录自启动方式源于Windows中的一个目录,这个目录一般叫启动或者Startup。位于该目录下的PE文件会在开机后进行自启动 ... [详细]
  • 系统数据实体验证异常:多个实体验证失败的错误处理与分析
    在使用MVC和EF框架进行数据保存时,遇到了 `System.Data.Entity.Validation.DbEntityValidationException` 错误,表明存在一个或多个实体验证失败的情况。本文详细分析了该错误的成因,并提出了有效的处理方法,包括检查实体属性的约束条件、调试日志的使用以及优化数据验证逻辑,以确保数据的一致性和完整性。 ... [详细]
  • MATLAB字典学习工具箱SPAMS:稀疏与字典学习的详细介绍、配置及应用实例
    SPAMS(Sparse Modeling Software)是一个强大的开源优化工具箱,专为解决多种稀疏估计问题而设计。该工具箱基于MATLAB,提供了丰富的算法和函数,适用于字典学习、信号处理和机器学习等领域。本文将详细介绍SPAMS的配置方法、核心功能及其在实际应用中的典型案例,帮助用户更好地理解和使用这一工具箱。 ... [详细]
  • MyISAM和InnoDB是MySQL中最为广泛使用的两种存储引擎,每种引擎都有其独特的优势和适用场景。MyISAM引擎以其简单的结构和高效的读取速度著称,适用于以读操作为主、对事务支持要求不高的应用。而InnoDB引擎则以其强大的事务处理能力和行级锁定机制,在需要高并发写操作和数据完整性的场景下表现出色。选择合适的存储引擎应综合考虑业务需求、性能要求和数据一致性等因素。 ... [详细]
  • 在C#中开发MP3播放器时,我正在考虑如何高效存储元数据以便快速检索。选择合适的数据结构,如字典或数组,对于优化性能至关重要。字典能够提供快速的键值对查找,而数组则在连续存储和遍历方面表现优异。根据具体需求,合理选择数据结构将显著提升应用的响应速度和用户体验。 ... [详细]
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社区 版权所有