网格grid的分享和总结(参考web前端微信公众号内容)
<!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!
相关推荐
戴翔的技术 2020-05-18
齐天大圣数据候 2020-05-16
过时不侯的温暖 2020-05-08
浪味仙 2020-04-20
戴翔的技术 2020-03-04
zengfanpei 2020-02-20
cbao 2020-02-14
xiaonao00 2020-01-02
xiaonao00 2019-12-25
cbao 2019-12-12
浪味仙 2019-12-10
maodouhuasheng 2019-12-04
且听真言 2019-12-01
ywwazyj 2019-11-15
badroot 2019-11-18
badroot 2019-11-17
zhichijunjun 2019-11-13
wjeymiantan 2019-11-07