媒体查询之响应式布局一

媒体查询

媒体查询:
根据设备的宽度(浏览器的宽度)来显示不同的css样式。
注意点:默认样式需要写在最前面。

常见的设备以下:
all (所有的设备) —使用频率最高。
print (打印设备)
screen (电脑屏幕,平板电脑,智能手机)

实现横竖屏幕的body样式搭配:

orientation —方向 portrait—竖 landscape— 横
方法1:

    @media screen and (orientation:portrait) {
      body {
        font-size: 14px;
        background: yellow;
      }
    }

    @media screen and (orientation: landscape) {
      body {
        font-size: 20px;
        background: blue;
      }
    }

方法2:

  <link rel="stylesheet" href="./css/style1.css" media="all and (orientation:portrait)">
  <link rel="stylesheet" href="./css/style2.css" media="all and (orientation:landscape)">

响应式布局一:

根据媒体查询,判断视口的大小,来改变div的显示多少。
HTML

 <section>
    <div>
      <img src="./image/pic2.png" alt="">
      <h3>笑意</h3>
    </div>
    <div>
      <img src="./image/pic2.png" alt="">
      <h3>笑意</h3>
    </div>
    <div>
      <img src="./image/pic2.png" alt="">
      <h3>笑意</h3>
    </div>
    <div>
      <img src="./image/pic2.png" alt="">
      <h3>笑意</h3>
    </div>
    ........
</section>

CSS

  <style>
    * {
      margin: 0;
      padding: 0;

    }

    img {
      display: block;
      width: 100%;
    }

    section {
      min-width: 1200px;
      height: 500px;
      background: #ccc;
      margin: 0 auto;
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
    }

    div {
      /* 使用媒体查询,时时改变div的宽度即可,便能实现响应式 */
      width: 23%;
      margin-bottom: 10px;
    }

    @media screen and (min-width: 1024px) and (max-width: 1200px) {
      section div {
        width: 23%;
      }
    }

    @media screen and (min-width: 750px) and (max-width: 1023px) {
      section div {
        width: 32%;
      }
    }

    @media screen and (min-width: 480px) and (max-width: 749px) {
      section div {
        width: 48%;
      }
    }

    @media screen and (max-width: 479px) {
      section div {
        width: 98%;
      }
    }
  </style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值