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
  • 包含哪幾種
  • 範例:Media Type 是 print
  • 媒體類型(Media Type) 的套用方式
  • 方式一:設定 media 屬性
  • 方式二:寫在 CSS 中
  1. 3 Media Query

3.1 媒體類型 Media Type

包含哪幾種

  • all:所有類型都包含。

  • screen:針對螢幕裝置。

  • print:用於列印時。

範例:Media Type 是 print

使用 print 這 media type 來指定列印時,要套用的 CSS:

h1{
  border: 1px solid red;
  color: red;
}

/* 使用 print 這 media type 來指定列印時,要套用的 CSS */
@media print {
  h1{
    border: 1px solid blue;
    color: blue;
  }
}

媒體類型(Media Type) 的套用方式

一般來說,沒有特別指定的話,Media Type 預設都是 all,也就是不管任何情況,都會套用。

如果要指定 Media Type 的話,可按照以下方式來指定:

方式一:設定 media 屬性

在 HTML 中:(主要是加上 media 屬性)

<link rel="stylesheet" href="abc.css" media="print">

<!-- 或 -->
<style media="print">
  /* 其它 CSS */
</style>

如果要指定複數個媒體類型(Media Type),以半形逗號做區隔即可:

<link rel="stylesheet" href="abc.css" media="screen, print">

<!-- 或 -->
<style media="screen, print">
  /* 其它 CSS */
</style>

方式二:寫在 CSS 中

在 CSS 中:(設定 @import 或 @media 語法都可)

/* 只有在列印時,才會套用 */
@import url("abc.css") print;

/* 或以下這個寫法 */
@media print {
  /* 其它 CSS */
}

如果是複數個 Media Type:

/* 指定在螢幕或列印時,才會套用 */
@import url("abc.css") screen, print;

/* 或以下這個寫法 */
@media screen, print {
  /* 其它 CSS */
}
Previous3 Media QueryNext3.2 媒體描述 Media Features

Last updated 1 year ago

Media Query 使用 Media Type 為 print(列印時)