为不同尺寸设备的不同 CSS 样式规则设置媒体查询


要为不同的 CSS 样式规则设置媒体查询,你可以尝试运行以下代码 −

例如

实时演示

<html>
   <head>
      <style>
         body {
            background-color: lightpink;
         }
         @media screen and (max-width: 420px) {
            body {
               background-color: lightblue;
            }
         }
      </style>
   </head>
   <body>
      <p>If screen size is less than 420px, then it will show lightblue color, or else it will show light pink color</p>
   </body>
</html>

更新于:2020-06-29

209 次浏览

启动你的 职业生涯

完成课程即可获得认证

开始
广告