Responsive Web Design
  • Responsive Web Design 課程
  • 1 簡介
    • 1.1 講者簡介
    • 1.2 課程簡介
  • 2 版面概念解析
  • 3 Media Query
    • 3.1 媒體類型 Media Type
    • 3.2 媒體描述 Media Features
    • 3.3 練習
  • 4 Viewport
    • 4.1 Viewport 定義
    • 4.2 HTML Viewport Meta
  • 5 Bootstrap Grid System
    • 5.1 載入 Grid 相關 CSS
    • 5.2 Grid System
    • 5.3 breakpoint 練習
  • 6 Transition 轉場效果
    • 6.1 第一個 transition
    • 6.2 transition-property
    • 6.3 transition-duration
    • 6.4 transition-timing-function
    • 6.5 transition-delay
    • 6.6 transition 簡寫
    • 6.7 練習
  • 7 Grid 排版模式
    • 7.1 基本觀念及術語
    • 7.2 Grid Container
    • 7.3 Grid Items
    • 7.4 練習
  • 8 Animation 動畫效果
    • 8.1 第一個 animation
    • 8.2 關於 keyframes
    • 8.3 相同元素套用多個 animation
    • 8.4 animation-iteration-count
    • 8.5 animation-direction
    • 8.6 animation-delay
    • 8.7 animation-fill-mode
    • 8.8 animation-play-state
    • 8.9 animation-timing-function
    • 8.10 animation 簡寫
    • 8.11 練習
  • 9 練習
  • 10 RWD 作業
  • 11 手機連本機端網站
  • 12 參考資料
  • 13 補充:AOS
Powered by GitBook
On this page
  • 範例 1:min-width
  • 範例 2:max-width
  • 範例 3:結合 min-width 與 max-width
  • 範例 4:結合 Media Type
  • 範例 5:Media Query 的「或」
  • 範例 6:orientation
  1. 3 Media Query

3.2 媒體描述 Media Features

Previous3.1 媒體類型 Media TypeNext3.3 練習

Last updated 1 year ago

範例 1:min-width

當螢幕寬度大於等於 768px 時,連結<a> 的文字顏色會變成紅色。

沒有寫 Media Type 的話,預設都是 all:

@media (min-width: 768px){
  a{
    color: red;
  }
}

以上的原始碼,如果加上 Media Type 的會,等同於以下:

@media all and (min-width: 768px){
  a{
    color: red;
  }
}

例:

範例 2:max-width

當螢幕寬度小於等於 767.98px 時,連結<a> 的文字顏色會變成綠色。

@media (max-width: 767.98px){
  a{
    color: green;
  }
}

例:

範例 3:結合 min-width 與 max-width

當螢幕寬度大於等於 768px 且小於等於 991.98px 時,連結<a> 的文字顏色會變成橘色。

@media (min-width: 768px) and (max-width: 991.98px){
  a{
    color: orange;
  }
}

例:

範例 4:結合 Media Type

當是螢幕時,螢幕寬度大於等於 768px 且小於等於 991.98px 時,連結<a> 的文字顏色會變成紅色。

@media screen and (min-width: 768px) and (max-width: 991.98px){
  a{
    color: red;
  }
}

例:

範例 5:Media Query 的「或」

以半型逗號做分隔。

@media screen and (min-width: 1200px), screen and (max-width: 767.98px){
  p{
    color: blue;
  }
}

範例 6:orientation

orientation 可以設定當手持裝置是橫向或縱向時,需要套用的 CSS,可以設定的值有:

  • portrait (縱向)

  • landscape (橫向)

註:即使是桌面裝置,若高度 > 寬度時,會視為直向;寬度 > 高度時,視為橫向。

當是螢幕時,且設備為橫向(landscape)擺放時,連結 <a> 的文字顏色會是紅色;反之,若設備為直向(portrait)擺放時,會是藍色。

@media screen and (orientation: landscape) {
  a{
    color: red;
  }
}

@media screen and (orientation: portrait) {
  a{
    color: blue;
  }
}

示範 Media Query 的 orientation