display:grid 是一种新的布局方式,旧的布局方式通常有副作用,例如float(需要额外修复浮动)或者inline-block(两个元素之间的空格问题)

 
把父元素定义为grid,就像表格一样,然后就可以给他的子元素定义各自占的行和列
.area {
     display: -ms-grid; /* prefix for IE 10 */
     display: grid; /* or inline-grid */
}
 
不需要改动标签就可以通过纯css实现表格布局
 
目前只有ie10支持
 
相关属性(有些用于父元素,有些则用于子元素):
grid-row / grid-column
grid-row-align / grid-column-align
grid-row-span / grid-column-span
grid-rows / grid-columns
 
这里面有个特别的单位:fr    类似于百分比
官方定义:the distribution of fractional space occurs after all 'length' or content-based row and column sizes have reached their maximum.
 
 
下面这些属性还没有任何浏览器支持:
grid-template: allows grid definition through a template of identifiers
grid-column-position: current grid-column since grid-column is supposed to be a shorthand for grid-column-position and grid-column-span
grid-row-position: same as above
grid-position: shorthand for grid-column-position and grid-row-position
grid-span: shorthand for grid-column-span and grid-row-span
grid-area: shorthand for grid-column-position, grid-row-position, grid-column-span and grid-row-span
grid-auto-columns: change default size for columns
grid-auto-rows: change default size for rows
grid-auto-flow: allows grid-items to automatically flow in available cells
 
 
例子:
* { box-sizing: border-box; }
html, body {
  height: 100%;
}
body {
  padding: 10px;
  display: -ms-grid;
  -ms-grid-columns: 200px 15px 1fr 15px 100px;
  -ms-grid-rows: auto 15px auto 15px auto;
}
.content {
  background: beige;
  padding: 0;
}
.header {
  background: tomato;
  -ms-grid-column-span: 5;
  -ms-grid-row: 1;
}
.footer {
  background: deepskyblue;
}

.footer {
  background: deepskyblue;
  -ms-grid-row: 5;
  -ms-grid-column-span: 5;

}
.main {
  background: orangered;
  -ms-grid-column: 3;
  -ms-grid-row: 3;
}
.sidebar {
  background: lightgreen;
  -ms-grid-column: 1;
  -ms-grid-row: 3;
}
.ads {
  background: gold;
  -ms-grid-column: 5;
  -ms-grid-row: 3;
}
h2 {
  margin-top: 0;
}
img {
  display: block;
  max-width: 100%;
  width: auto;
  margin: 0 auto 10px;
}
div {
  color: white;
  padding: 10px;
}
p {
  margin: 0 0 1em 0;
}
@media all and (max-width: 600px) {
  body {
    -ms-grid-columns: 1fr;
    -ms-grid-rows: auto (1% auto)[4];
  }
  .header, .ads, .sidebar, .main, .footer {
    -ms-grid-column: 1;
  }
  .header  { -ms-grid-row: 1; }
  .ads     { -ms-grid-row: 3; }
  .main    { -ms-grid-row: 5; }
  .sidebar { -ms-grid-row: 7; }
  .footer  { -ms-grid-row: 9; }
  .ads {
    display: -ms-grid;
    -ms-grid-columns: 1% (32% 1%)[3];
    -ms-grid-rows: 2;
  }
  .ads h2 { -ms-grid-row: 1; -ms-grid-column-span: 3; }
  .ads img { margin: 0; -ms-grid-row: 2; }
  .ads img:nth-of-type(1) { -ms-grid-column: 2; }
  .ads img:nth-of-type(2) { -ms-grid-column: 4; }
  .ads img:nth-of-type(3) { -ms-grid-column: 6; }
}
<div class="sidebar"><h2>Sidebar</h2></div>
<div class="main">
   <h2>Main</h2>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> 
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> 
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> 
</div>
<div class="footer"><h2>Footer</h2></div>
<div class="header"><h2>Header</h2></div>
<div class="ads">
  <h2>Ads</h2>
  <img src="http://lorempixel.com/200/200/business/" />
  <img src="http://lorempixel.com/200/200/city/" />
  <img src="http://lorempixel.com/200/200/animals/" />
</div>

grid 布局 CSS3的更多相关文章

  1. [转]使用CSS3 Grid布局实现内容优先

    使用CSS3 Grid布局实现内容优先  http://www.w3cplus.com/css3/css3-grid-layout-module.html 本文由大漠根据Rachel Andrew的& ...

  2. css3 flex布局/grid布局

    1.CSS3 Flexbox 布局完全指南(图解 Flexbox 布局详细教程) 2.CSS Grid 布局完全指南(图解 Grid 详细教程)

  3. CSS3 Flex布局和Grid布局

      1 flex容器的六个属性 flex实现垂直居中: <div class="box"> <span class="item">< ...

  4. 理解css中Grid布局,在项目中如何实现grid页面布局

    简介 CSS中Grid是一种二维网格式布局方式.我们常规使用table.float.position.inline-block等布局,但它们遗漏了很多功能,例如垂直居中.后来css3中flexbox的 ...

  5. WPF中Grid布局

    WPF中Grid布局XMAl与后台更改,最普通的登录界面为例. <Grid Width="200" Height="100" > <!--定义 ...

  6. CSS判断不同分辨率显示不同宽度布局CSS3技术支持IE6到IE8

    CSS判断不同分辨率浏览器(显示屏幕)显示不同宽度布局CSS3技术支持IE6到IE8.将用到css3 @media样式进行判断,但IE9以下版本不支持CSS3技术,这里DIVCSS5给大家介绍通过JS ...

  7. wpf后置代码中的Grid布局以及图片路径的设置

    之前用Grid练习连连看布局时,遇到了几个困惑.此次就把当时的一些收获写出来,供以后翻看. 图片路径可能比较常用,所以就写在第一个了. 在xaml中,设置图片非常简单,只要把图片拷贝到资源目录(这里假 ...

  8. css grid布局的首次使用

    首先来看一下效果图 接下来废话不多说,先上代码 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  9. 学习ExtJS的grid布局

    这是之前学习ExtJS布局的时候我导师让我重点熟悉的内容.之后会发一个最近写的结合MVC项目的grid布局的案例. 上一篇关于ExtJS的学习资料什么的都已经更在上一篇了,这里只是对一些代码的记录. ...

随机推荐

  1. C++运算符优先级 案例1

    问: ... short nReaderCount=10              ++pLock->nReaderCount==? ...++和->同为1级优先级,我想很多也有很多新手弄 ...

  2. win32多线程编程

    关于多线程多进程的学习,有没有好的书籍我接触的书里头关于多线程多进程部分,一是<操作系统原理>里面讲的相关概念   一个是<linux基础教程>里面讲的很简单的多线程多进程编程 ...

  3. uva 1121 Subsequence

    https://vjudge.net/problem/UVA-1121 题意: 给出一个正整数数列a,要求找出最短的连续的一个序列使得这个序列的所有数字之和大于等于S. 思路: 第一是由于序列都是正整 ...

  4. 原创:TSP问题解决方案-----禁忌搜索算法C实现

    本文着重于算法的实现,对于理论部分可自行查看有关资料可以简略参考该博文:http://blog.csdn.net/u013007900/article/details/50379135 本文代码部分基 ...

  5. python堆栈实现

    百度百科定义: 堆栈是一个在计算机科学中经常使用的抽象数据类型.堆栈中的物体具有一个特性: 最后一个放入堆栈中的物体总是被最先拿出来, 这个特性通常称为后进先出(LIFO)队列. 堆栈中定义了一些操作 ...

  6. 简单又炫酷的two.js 二维动画教程

      前  言 S     N 今天呢给大家介绍一个小js框架,Two.JS.其实在自己学习的过程中并没有找到合适的教程,所以我这种学习延迟的同学是有一定难度的,然后准备给大家整理一份,简单易懂的小教程 ...

  7. 我的第一篇blog—— 一起来赛马呀

      作为一名大三的学生现在开始学习acm,或许太晚.感叹时光蹉跎....我的blog将以讲解的形式的发布,以专题的形式的形式介绍一些基本的知识和经典的题目.虽然感觉自己所剩时间无多,但也希望起到前人种 ...

  8. Java历程-初学篇 Day07 循环结构2 for循环

    一,格式 for(赋值语句//为循环变量赋初值;条件语句//循环结构的循环条件;赋值语句//迭代,修改循环变量的值){ //循环体; } 二,简单举例 for(int i=1;i<=10;i++ ...

  9. IIS 500错误或无法显示此网页解决方法

    不知道是不是XP版本的原故,发现越来越多的XP系统装好IIS后连默认网站都打不开,(其他系统没有注意)出现几个大字,IIS 500错误.相信碰到这个问题的人都深有体会,确实很烦人.卸了IIS重装也是不 ...

  10. Python面试题之python是一种什么语言及优缺点

    1.说说python是一种什么语言? 参考答案:python是一门动态解释性的强类型定义语言 编译型vs解释型 编译型优点:编译器一般会有预编译的过程对代码进行优化.因为编译只做一次,运行时不需要编译 ...