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. Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  2. Erlang游戏服设计总结

    这主要是一年多来,个人从事Erlang游戏服开发中对一些事情的思考. 想到哪说到哪,没有条理可言. 欢迎讨论. 通常Erlang游戏服务的设计涉及到的东东包括如下: 任务系统 活动系统 公会系统 玩法 ...

  3. SQL监测语句

    SELECT top 20 qs.creation_time,last_execution_time,total_physical_reads,total_logical_reads,total_lo ...

  4. HDU3336 Count the string

    居然一A了,说明对朴素的KMP还是有一定理解. 主要就是要知道next数组的作用,然后就可以计算每个i结尾的满足题意的串个数. #include<cstdio> #include<c ...

  5. QQ--基于TCP/UDP协议的通讯原理

    QQ是一个基于TCP/UDP协议的通讯软件  发送消息的时候是UDP打洞,登陆的时候使用HTTP~因为登陆服务器其实就是一个HTTP服 务器,只不过不是常用的那些,那个服务器是腾讯自行开发的!   一 ...

  6. cocos2dx - 控件扩展之pageview循环显示

    接上一节内容:cocos2dx - shader实现任意动画的残影效果 本节主要讲一下扩展PageView控件功能 在实际游戏应用中,经常会碰到用原来的控件难以实现的功能.这时候就需要根据需求,通过选 ...

  7. configparser模块(拷贝)

    该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 创建文件 来看一个好多软件的常见文档格式如下: [DEFAULT] ...

  8. Ubuntu14.04LTS下安装Node.js&NPM以及个人博客hexo的初始化配置

    什么是hexo Hexo 是一款基于node 的静态博客网站生成器作者 :tommy351是一个台湾的在校大学生...相比其他的静态网页生成器而言有着,生成静态网页最快,插件丰富(已经移植了大量Oct ...

  9. hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)

    SDUST的训练赛 当时死磕这个水题3个小时,也无心去搞其他的 按照题意,转换成无向图,预处理去掉单向的边,然后判断剩下的图能否构成两个无向完全图(ps一个完全图也行或是一个完全图+一个孤点) 代码是 ...

  10. MySQL数据库分区的概念与2大好处(1)

    我们大家都知道通过MySQL数据库分区(Partition)可以提升MySQL数据库的性能,那么到底什么是MySQL数据库分区呢?以及其实际应用的好处的表现有哪些呢?以下的文章就是对这些内容的描述. ...