為不同的尺寸裝置設定適合不同 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>

更新於: 29-Jun-2020

209 次瀏覽

開始你的職業

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.