使用 CSS3 的媒体查询

cssweb developmentfront end technology更新于 2024/2/10 21:00:17

媒体查询针对不同尺寸的设备(例如移动设备、桌面设备等)采用不同的样式规则。

您可以尝试运行以下代码,使用 CSS3 实现媒体查询 −

示例


<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>

相关文章


有用资源