代码
提交代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .demo{ display:grid; grid-template-columns: 100px 100px; grid-template-rows:none; grid-auto-rows: 50px; color:#fff; text-align: center; } .item:nth-of-type(1){ background: red; } .item:nth-of-type(2){ background: green; } .item:nth-of-type(3){ background: purple; } .item:nth-of-type(4){ background: yellowgreen; } </style> </head> <body> <div class="demo"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> </div> </body> </html>
运行结果