- Material Design Lite 教程
- MDL - 首頁
- MDL - 概述
- MDL - 環境設定
- MDL - 佈局
- MDL - 網格
- MDL - 標籤頁
- MDL - 頁尾
- MDL - 徽章
- MDL - 按鈕
- MDL - 卡片
- MDL - 進度條
- MDL - 載入動畫
- MDL - 選單
- MDL - 滑塊
- MDL - 複選框
- MDL - 單選按鈕
- MDL - 圖示
- MDL - 開關
- MDL - 資料表格
- MDL - 文字欄位
- MDL - 工具提示
- Material Design Lite 資源
- MDL - 快速指南
- MDL - 有用資源
- MDL - 討論
Material Design Lite 佈局
本章將討論 Material Design Lite 中的不同佈局。HTML5 有以下容器元素:
<div> − 為 HTML 內容提供通用容器。
<header> − 代表頁首部分。
<footer> − 代表頁尾部分。
<article> − 代表文章。
<section> − 為各種型別的部分提供通用容器。
MDL 提供各種 CSS 類來為容器應用各種預定義的視覺和行為增強功能。下表列出了可用的類及其效果。
| 序號 | 類名及描述 |
|---|---|
| 1 | mdl-layout 將容器標識為 MDL 元件。外層容器元素需要此類。 |
| 2 | mdl-js-layout 為佈局新增基本的 MDL 行為。外層容器元素需要此類。 |
| 3 | mdl-layout__header 將容器標識為 MDL 元件。頁首元素需要此類。 |
| 4 | mdl-layout-icon 用於新增應用程式圖示。如果兩者都可見,則會被選單圖示覆蓋。可選圖示元素。 |
| 5 | mdl-layout__header-row 將容器標識為 MDL 頁首行。頁首內容容器需要此類。 |
| 6 | mdl-layout__title 標識佈局標題文字。佈局標題容器需要此類。 |
| 7 | mdl-layout-spacer 用於對齊頁首或抽屜內的元素。它會擴充套件以填充剩餘空間。通常用於將元素右對齊。在佈局標題後的 div 上可選。 |
| 8 | mdl-navigation 將容器標識為 MDL 導航組。nav 元素需要此類。 |
| 9 | mdl-navigation__link 將錨點標識為 MDL 導航連結。頁首和/或抽屜錨點元素需要此類。 |
| 10 | mdl-layout__drawer 將容器標識為 MDL 佈局抽屜。抽屜容器元素需要此類。 |
| 11 | mdl-layout__content 將容器標識為 MDL 佈局內容。主元素需要此類。 |
| 12 | mdl-layout__header--scroll 使頁首隨內容滾動。頁首元素可選。 |
| 13 | mdl-layout--fixed-drawer 使抽屜始終可見並在較大螢幕上開啟。外層容器元素可選,抽屜容器元素不需要。 |
| 14 | mdl-layout--fixed-header 使頁首始終可見,即使在小螢幕上也是如此。外層容器元素可選。 |
| 15 | mdl-layout--large-screen-only 在較小螢幕上隱藏元素。mdl-layout 的任何子元素上均可選。 |
| 16 | mdl-layout--small-screen-only 在較大螢幕上隱藏元素。mdl-layout 的任何子元素上均可選。 |
| 17 | mdl-layout__header--waterfall 允許使用多行頁首的“瀑布”效果。頁首元素可選。 |
| 18 | mdl-layout__header--transparent 使頁首透明並在佈局背景之上繪製。頁首元素可選。 |
| 19 | mdl-layout__header--seamed 使用沒有陰影的頁首。頁首元素可選。 |
| 20 | mdl-layout__tab-bar 將容器標識為 MDL 標籤欄。頁首內(選項卡式佈局)的容器元素需要此類。 |
| 21 | mdl-layout__tab 將錨點標識為 MDL 標籤連結。標籤欄錨點元素需要此類。 |
| 22 | is-active 將標籤標識為預設活動標籤。標籤欄錨點元素和關聯的標籤部分元素可選。 |
| 23 | mdl-layout__tab-panel 將容器標識為標籤內容面板。標籤部分元素需要此類。 |
| 24 | mdl-layout--fixed-tabs 使用固定標籤而不是預設的可滾動標籤。外層容器元素可選,頁首內的容器不需要。 |
以下示例顯示了使用 mdl-layout 類來設定各種容器樣式。
固定抽屜
要建立具有固定抽屜但沒有頁首的模板,請使用以下 MDL 類。
mdl-layout − 將 div 標識為 MDL 元件。
mdl-js-layout − 為外層 div 新增基本的 MDL 行為。
mdl-layout--fixed-drawer − 使抽屜始終可見並在較大螢幕上開啟。
mdl-layout__drawer − 將 div 標識為 MDL 佈局抽屜。
mdl-layout-title − 標識佈局標題文字。
mdl-navigation − 將 div 標識為 MDL 導航組。
mdl-navigation__link − 將錨點標識為 MDL 導航連結。
mdl-layout__content − 將 div 標識為 MDL 佈局內容。
mdl_fixeddrawer.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- No header, and the drawer stays open on larger screens (fixed drawer).-->
<div class = "mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<div class = "page-content" style = "padding-left:100px;">Hello World!</div>
</main>
</div>
</body>
</html>
結果
驗證結果。
固定頁首
要建立具有固定頁首的模板,請使用以下附加 MDL 類。
mdl-layout--fixed-header − 使頁首始終可見,即使在小螢幕上也是如此。
mdl_fixedheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- Always shows a header, even in smaller screens. -->
<div class = "mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class = "mdl-layout__header">
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<!-- Add spacer, to align navigation to the right -->
<div class = "mdl-layout-spacer"></div>
<!-- Navigation -->
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = ""
style = "color:gray">Home</a>
<a class = "mdl-navigation__link" href = ""
style = "color:gray">About</a>
</nav>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<div class = "page-content">Hello World!</div>
</main>
</div>
</body>
</html>
結果
驗證結果。
固定頁首和抽屜
要建立具有固定頁首和固定抽屜的模板,請使用以下附加 MDL 類。
mdl-layout--fixed-drawer − 使抽屜始終可見並在較大螢幕上開啟。
mdl-layout--fixed-header − 使頁首始終可見,即使在小螢幕上也是如此。
mdl_fixedheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- The drawer is always open in large screens. The header is always
shown, even in small screens. -->
<div class = "mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
<header class = "mdl-layout__header">
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<!-- Add spacer, to align navigation to the right -->
<div class = "mdl-layout-spacer"></div>
<!-- Navigation -->
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = ""
style = "color:gray">Home</a>
<a class = "mdl-navigation__link" href = ""
style = "color:gray">About</a>
</nav>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<div class = "page-content">Hello World!</div>
</main>
</div>
</body>
</html>
結果
驗證結果。
滾動頁首
要建立具有滾動頁首的模板,請使用以下 MDL 類。
mdl-layout--header--scroll − 使頁首隨內容滾動。
mdl_scrollingheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- Uses a header that scrolls with the text, rather than
staying locked at the top -->
<div class = "mdl-layout mdl-js-layout ">
<header class = "mdl-layout__header mdl-layout__header--scroll">
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<!-- Add spacer, to align navigation to the right -->
<div class = "mdl-layout-spacer"></div>
<!-- Navigation -->
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<div class = "page-content" style = "padding-left:100px;">Hello World!
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
</div>
</main>
</div>
</body>
</html>
結果
驗證結果。
收縮頁首
要建立頁面向下滾動時會收縮的頁首模板,請使用以下 MDL 類。
mdl-layout__header--waterfall − 允許使用多行頁首的“瀑布”效果。
mdl_waterfallheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- The drawer is always open in large screens. The header is always
shown, even in small screens. -->
<div class = "mdl-layout mdl-js-layout ">
<header class = "mdl-layout__header mdl-layout__header--waterfall">
<!-- Top row, always visible -->
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<!-- Add spacer, to align navigation to the right -->
<div class = "mdl-layout-spacer"></div>
</div>
<!-- Bottom row, not visible on scroll -->
<div class = "mdl-layout__header-row">
<div class = "mdl-layout-spacer"></div>
<!-- Navigation -->
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<div class = "page-content" style = "padding-left:100px;">Hello World!
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
<br/><br/><br/><br/><br/><br/><br/><br/>...
</div>
</main>
</div>
</body>
</html>
結果
驗證結果。
具有可滾動標籤的固定頁首
要建立具有包含可滾動標籤的頁首的模板,請使用以下 MDL 類。
mdl-layout__tab-bar − 將容器標識為 MDL 標籤欄。
mdl-layout__tab − 將錨點標識為 MDL 標籤連結。
mdl-layout__tab-panel − 將容器標識為標籤內容面板。
mdl_scrollabletabheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- The drawer is always open in large screens. The header is always
shown, even in small screens. -->
<div class = "mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class = "mdl-layout__header">
<!-- Top row, always visible -->
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
</div>
<!-- Tabs -->
<div class = "mdl-layout__tab-bar mdl-js-ripple-effect">
<a href = "#scroll-tab-1" class = "mdl-layout__tab is-active">Tab 1</a>
<a href = "#scroll-tab-2" class = "mdl-layout__tab">Tab 2</a>
<a href = "#scroll-tab-3" class = "mdl-layout__tab">Tab 3</a>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<section class = "mdl-layout__tab-panel is-active" id = "scroll-tab-1">
<div class = "page-content">Tab 1 Contents</div>
</section>
<section class = "mdl-layout__tab-panel" id = "scroll-tab-2">
<div class = "page-content">Tab 2 Contents</div>
</section>
<section class = "mdl-layout__tab-panel" id = "scroll-tab-3">
<div class = "page-content">Tab 3 Contents</div>
</section>
</main>
</div>
</body>
</html>
結果
驗證結果。
具有固定標籤的固定頁首
要建立具有包含固定標籤的頁首的模板,請使用以下附加 MDL 類。
mdl-layout--fixed-tabs − 使用固定標籤而不是預設的可滾動標籤。
mdl_fixedtabheader.htm
<html>
<head>
<link rel = "stylesheet"
href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
<script src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
</script>
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<!-- The drawer is always open in large screens. The header is always
shown, even in small screens. -->
<div class = "mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-tabs">
<header class = "mdl-layout__header">
<!-- Top row, always visible -->
<div class = "mdl-layout__header-row">
<!-- Title -->
<span class = "mdl-layout-title">HTML5 Tutorial</span>
</div>
<!-- Tabs -->
<div class = "mdl-layout__tab-bar mdl-js-ripple-effect">
<a href = "#scroll-tab-1" class = "mdl-layout__tab is-active">Tab 1</a>
<a href = "#scroll-tab-2" class = "mdl-layout__tab">Tab 2</a>
<a href = "#scroll-tab-3" class = "mdl-layout__tab">Tab 3</a>
</div>
</header>
<div class = "mdl-layout__drawer">
<span class = "mdl-layout-title">HTML5 Tutorial</span>
<nav class = "mdl-navigation">
<a class = "mdl-navigation__link" href = "">Home</a>
<a class = "mdl-navigation__link" href = "">About</a>
</nav>
</div>
<main class = "mdl-layout__content">
<section class = "mdl-layout__tab-panel is-active" id = "scroll-tab-1">
<div class = "page-content">Tab 1 Contents</div>
</section>
<section class = "mdl-layout__tab-panel" id = "scroll-tab-2">
<div class = "page-content">Tab 2 Contents</div>
</section>
<section class = "mdl-layout__tab-panel" id = "scroll-tab-3">
<div class = "page-content">Tab 3 Contents</div>
</section>
</main>
</div>
</body>
</html>
結果
驗證結果。