search
HomeWeb Front-endHTML Tutorialbootstrap之栅格系统_html/css_WEB-ITnose


title: bootstrap之栅格系统date: 2016-06-06 22:37:43tags:

- bootstrap 基础- bootstrap 栅格

接着之前的bootstrap基础部分继续,今天这里主要是关于bootstrap中栅格系统,其实bootstrap主要是应用与响应式的,说到响应式大家都会想到媒体查询@media:没错这里的关键点那就是媒体查询@media(废话不多说了,直接进入正题);

媒体查询 阈值(注意:例子中阈值都为默认值)

首先我们要知道bootstrap为我们提供了一套完整的流体栅格系统,而且随这屏幕或者视扣尺寸的增加,系统会制动分成最多12列 记住最多12列,当然有人会问多出了怎么办?别急下面且看我给您慢慢道来:首先了解一下bootstrap媒体查询的阈值来跟我念 yu值 第三声 ,不是阀(fa)值,哈哈哈~~~,

/* 小屏幕(平板,大于等于 768px) */@media (min-width: @screen-sm-min) { ... }/* 中等屏幕(桌面显示器,大于等于 992px) */@media (min-width: @screen-md-min) { ... }/* 大屏幕(大桌面显示器,大于等于 1200px) */@media (min-width: @screen-lg-min) { ... }

上面的这些值得范围我们都是可以修改的,当这个范围达不到我们的需求时我们自己可以通过css样式来直接覆盖的;

@media (max-width: @screen-xs-max) { ... }@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }@media (min-width: @screen-lg-min) { ... }

下面是一些详细的参数(这里就偷一下懒,刷了张图)

Mou icon

实际例子:

呈现的效果就是当视口大于等于992px时就会水平排列,这里大家稍微注意一下就是所有"列"必须放在 .row内,向下面这样:

<style>.col-md-1{  background-color: #f1f1f1;  border:1px solid #1a2b3c;}.col-md-4{  background-color: #f1f1f1;  border:1px solid #1a2b3c;}.col-md-6{  background-color: #f1f1f1;  border:1px solid #1a2b3c;}.col-md-8{  background-color: #f1f1f1;  border:1px solid #1a2b3c;} </style><body>      <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></body>

大于992px

Mou icon

小于992px

Mou icon

移动设备和桌面

现在我们要适应两中不同的场景,所以一种类名现在已经不饿能够满足要求所以我们要再加一个类名像这样这里为了好分辨就给每个.row加了一个margin-bottom:10px;;具体代码如下:

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

具体效果:

大于992px

Mou icon

小于992px

Mou icon

手机、平板、桌面

现在我们又多一个场景,再次细分,同样的再添加一个类名(相当于再次多以个阈值);代码如下:

<div class="row">      <div class="col-xs-12 col-sm-6 col-md-8">.col-xs-12 .col-sm-6 .col-md-8</div>      <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div></div>

效果入下:

大于992px

Mou icon

小于992px且大于768px

Mou icon

小于768px

Mou icon

多余列

前面咱们提到过栅格系统做多为我们提供12列,那么超出部分怎么办哪? bootstrap这里是如果超出那么会将多余的元素作为整体再另起一列:例:

<!-- 对比列 --><div class="row">      <div class="col-xs-9">.col-xs-9</div>      <div class="col-xs-3">.col-xs-3 因为9 + 3 = 12 ,  </div>      <div class="col-xs-8">.col-xs-8  </div></div><!--效果列--><div class="row">      <div class="col-xs-9">.col-xs-9</div>      <div class="col-xs-4">.col-xs-4  因为9 + 4 = 13 > 12,所以多出来的会下来 </div>      <div class="col-xs-8">.col-xs-8  </div></div>

效果如下:

Mou icon

列偏移

其实列偏移就是改变当前元素的margin值:例:

<div class="row">      <div class="col-md-4">.col-md-4</div>      <div class="col-md-4 col-md-offset-4">我发生了偏移.col-md-offset-4</div></div><div class="row">      <div class="col-md-3 col-md-offset-3">我发生了偏移 .col-md-offset-3</div>      <div class="col-md-3 col-md-offset-3">我发生了偏移 .col-md-offset-3</div></div><div class="row">      <div class="col-md-6 col-md-offset-3">我发生了偏移 .col-md-offset-3</div></div>

具体效果如下:

Mou icon

嵌套列

有时候我们在开发项目时会遇到将内容嵌套,而bootstrap这里也是给我们提供嵌套类:

<div class="row">      <div class="col-sm-9">        父级 : .col-sm-9        <div class="row">              <div class="col-xs-8 col-sm-6">                    子集左 : .col-xs-8 .col-sm-6              </div>              <div class="col-xs-4 col-sm-6">                     子集右 : .col-xs-4 .col-sm-6              </div>            </div>      </div></div>

具体效果如下:

大于768px;

Mou icon

小于768px;

Mou icon

后面还会继续更新有关bootstrap的内容~~ 欢迎各位书友前来指正~ :> bye~

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

What is the purpose of the <iframe> tag? What are the security considerations when using it?What is the purpose of the <iframe> tag? What are the security considerations when using it?Mar 20, 2025 pm 06:05 PM

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

What is the viewport meta tag? Why is it important for responsive design?What is the viewport meta tag? Why is it important for responsive design?Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools