為不同尺寸裝置的不同 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 次瀏覽

啟動你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.