2. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites
3. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites
8. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites
9. %
RESIZING AN IMAGE USING
? Any Size?
用百分比取代直接定義大小。
div.img-wrap{
float: left;
width:100%;
}
img.responsive {
max-width: 100%;
height: auto;
}
11. RESIZING YOUR SITE USING
MEDIA QUERY
? 什麼是 Media Query?
偵測裝置的尺寸和方向,提供指定的 CSS 樣式
? 有兩種使用方法
? 在同一個 CSS 檔中,用 @media 判斷螢幕寬度,
載入相應的樣式
? 在 HTML 檔中定義不同大小對應的 External CSS 檔案
12. RESIZING YOUR SITE USING
MEDIA QUERY
? @media
Query 螢幕大小
/* 當螢幕寬度介於 1280 px ~ 1025 px 時 */
@media screen and ( min-width:1025px )
and ( max-width: 1280px ) {
img.responsive {
/* 圖片寬度為 900 px */
width: 900px;
}
}
img.responsive {
height: auto;
}
13. RESIZING YOUR SITE USING
MEDIA QUERY
? 也可以分成許多不同的 CSS 檔案
<link rel="stylesheet" type="text/css" href=“small.css"
media="screen and (max-width: 1024px)">
<link rel="stylesheet" type="text/css" href=“medium.css"
media="screen and (min-width: 1025px)
and (max-width: 1280px)">
<link rel="stylesheet" type="text/css" href=“large.css"
media="screen and (min-width: 1081px)">
15. RESIZING YOUR SITE USING
MEDIA QUERY
? 這是怎麼做到的?
在 HTML 中定義大小清單,在 CSS 中決定輸出樣式
<div class="small-menu">
<form>
<select >
<option value=“blog.html”>Option1</option>
<option value="home.html">Option2</option>
<option value="tutorials.html">Option3</option>
</select>
<form>
</div>
16. RESIZING YOUR SITE USING
MEDIA QUERY
? 這是怎麼做到的?
? 在 HTML 中定義大小清單,這是小清單的原始碼
<div class="small-menu">
<form>
<select >
<option value=“blog.html”>Option1</option>
<option value="home.html">Option2</option>
<option value="tutorials.html">Option3</option>
</select>
<form>
</div>
17. RESIZING YOUR SITE USING
MEDIA QUERY
? 這是怎麼做到的?
? 在 CSS 中決定兩種清單該什麼時候在什麼位置出現
@media screen and ( max-width: 800px ) {
.small-menu {
display: inline;
}
/* 把大清單藏起來 */
.large-menu {
display: none;
}
}
18. IT’S YOUR TURN!
? 用 Media Query 寫一隻簡單的網頁,讓它能跟著螢
幕大小轉換不同樣式
? Note: 可能會用到的工具
Window Resizer
19. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites
23. RECALL: MEDIA QUERIES
? Adding a media query to CSS
? Creating a responsive width layout with media queries
? Changing image sizes with media queries
? Hiding an element with media queries
25. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites
29. OUTLINE
? What is “Responsive Web Design” ?
? Responsive Elements and Media
? Responsive Layout
? Using Responsive Layout
? Building Mobile-first Websites