<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>网格布局Grid用法</title> <style> body{ width: 100%; height: 100%; display: flex; justify-content: center; } .gridtable{ display: grid; /* width: 100%;(容器的宽度能够规定也能够不固定,其中若不规定宽度则追溯到父集的宽度直至body ,高也同样*/ /* grid-template-columns: 30% 40% 30%; */ /*能够大于100%,也能够用实际的数值*/ /* grid-template-rows: 50px 60px ; */ /*能够大于100%,也能够用实际的数值*/ width: 400px; height: 400px; } .gridtable>div{ text-align: center; } .gridtable>div:nth-child(1){ background: deepskyblue; grid-column-start: 1; grid-column-end: 3; } .gridtable>div:nth-child(2){ background: deeppink; } .gridtable>div:nth-child(3){ background: darkcyan; grid-row-start: 2; grid-row-end: 4; } .gridtable>div:nth-child(4){ background: lightsalmon; grid-column-start: 2; grid-column-end: 4; } .gridtable>div:nth-child(5){ background: lightcoral; } .gridtable>div:nth-child(6){ background: darkseagreen; } </style> </head> <body> <div class="gridtable"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> </div> </body> </html>
第一张代码生成的页面图,第二张是我的对grid-column-start(end)中的column
的备注,其中黑线表明column,下方绿色数字表明个数,这样就很容易理解这行代码的意思了,同理可知row!html