使用 grid+媒体查询做响应式的例子

使用 grid+媒体查询做响应式

<div class="wrapper">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
.wrapper {
  /* 使用网格布局 */
  display: grid;
  /* 行和列的间距 */
  grid-gap: 10px; 
  /* 分为三行,每行高度50px */
  grid-template-rows: 50px 50px 50px;
}
.wrapper > div:nth-child(1) {
  background-color: aquamarine;
}
.wrapper > div:nth-child(2) {
  background-color: blanchedalmond;
}
.wrapper > div:nth-child(3) {
  background-color: chartreuse;
}
/* 最小宽度 1200px  */
@media (min-width: 1200px) {
  .wrapper {
  	/* 分为3列,每列宽30% */
    grid-template-columns: 30% 30% 30%;
  }
}
/* 最小宽度 768px */
@media (min-width: 768px) and (max-width: 1199px) {
  .wrapper {
  	/* 分为2列,每列宽45% */
    grid-template-columns: 45% 45%;
  }
  .wrapper > div:nth-child(3) {
  	/* 当前列从第1个网格开始到第3个网格结束 */
    grid-column: 1 / 3;
  }
}
/* 最小宽度 480px */
@media (min-width: 480px) and (max-width: 767px) {
  .wrapper {
  	/* 分为1列,每列100%宽 */
    grid-template-columns: 100%;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值