W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <style> .grid-container { display: grid; grid-gap: 10px; background-color: #2196F3; padding: 10px; } .grid-item { background-color: rgba(255, 255, 255, 0.8); text-align: center; padding: 20px; font-size: 30px; } .item1 { grid-column: 1 / span 2; grid-row: 1; } .item2 { grid-column: 3; grid-row: 1 / span 2; } .item5 { grid-column: 1 / span 3; grid-row: 3; } </style> </head> <body> <h1>五项目的网格布局:</h1> <div class="grid-container"> <div class="grid-item item1">1</div> <div class="grid-item item2">2</div> <div class="grid-item item3">3</div> <div class="grid-item item4">4</div> <div class="grid-item item5">5</div> </div> <p>网格容器的直接子元素自动成为网格项目。</p> <p>Item 1、2 以及 5 被设置为横跨多列或行。</p> </body> </html>