Upgrade to Pro — share decks privately, control downloads, hide ads and more …

模組基礎與常用 CSS.pdf

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Joseph Chiang Joseph Chiang
June 15, 2012
630

模組基礎與常用 CSS.pdf

Avatar for Joseph Chiang

Joseph Chiang

June 15, 2012
Tweet

Transcript

  1. <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div>

    <div class=”ft”> <a href=”...”>更多... </a> </div> </div> 模組的結構
  2. <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div>

    <div class=”ft”> <a href=”...”>更多... </a> </div> </div> <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div> </div> 模組的結構
  3. <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div>

    <div class=”ft”> <a href=”...”>更多... </a> </div> </div> <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div> </div> 模組的結構 ⼀一個 ID 代表⼀一個模組 不能重複
  4. <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div>

    <div class=”ft”> <a href=”...”>更多... </a> </div> </div> <div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div> </div> 模組的結構 ⼀一個 ID 代表⼀一個模組 不能重複 .hd, .bd, .ft 分別代表模組的 header、body、footer
  5. <div id=”ykpsb”> <div class=”bd clearfix”> <form ...> ... </form> <div

    class=”extra”> ... </div> </div> </div> form .extra [HTML] <style> #ykpsb { margin-bottom:10px; } #ykpsb form { float:left; } #ykpsb .extra { float:right; } </style> [CSS] 因每個模組有 id,所以 CSS 可以寫得很 namespace 好處就是很安全,不同模組不會互相干擾
  6. 練習 1:HTML 模組 (3 Mins) http://josephj.com/training/ncu/html-module.html 1. 替此文章模組取個適合的 id 2.

    加上 hd, bd, ft 的 class 3. 利用前頁的方法設定 CSS color:#369; background:#ffe; font:bold 16px;
  7. 現在:使用 CSS 的 float 屬性來做到 <div id=”masthead” style=”border:solid 1px #000”>

    <span style=”float:left”> 靠左文字 </span> <span style=”float:right”> 靠右文字 </span> </div> 靠左文字 靠右文字
  8. 對 IE 的解法: 對上⼀一層設 zoom:1 <div id=”masthead” style=”zoom:1;border:solid 1px #000”>

    <span style=”float:left”> 靠左文字 </span> <span style=”float:right”> 靠右文字 </span> </div>
  9. 對其他瀏覽器的解法: <div id=”masthead” style=”zoom:1;border:solid 1px #000”> <span style=”float:left”> 靠左文字 </span>

    <span style=”float:right”> 靠右文字 </span> </div> <style> /* 作用是增加了⼀一個有 clear:both 屬性的區塊 */ #masthead:after { content:’’; display:block; clear:both; } </style>
  10. 練習 2:CSS 浮動(3 Mins) http://josephj.com/training/ncu/float.html 1. 標題浮到左邊 2. YUI 圖浮到右邊

    3. 替整個模組設 border 4. 用前⼀一頁的方法清除 float border:solid 5px #ccc; font:bold 197%; IE : 在父節點設定 zoom1; 父節點: 父節點:after { content:’’; display:block; clear:both; }
  11. background:[背景色] [url(圖檔路徑)] [x, y 位置] [重複]; background:#369 url(ico_yui.gif) left top

    repeat-x; repeat-y no-repeat 0 100% 0 -12px background-color:#369; background-image:url(ico_yui.gif); background-position:left top; background-repeat:repeat-x; 或
  12. • position • position:static; 預設 • position:absolute; 絕對定位 • position:relative;

    相對定位 • position:fixed; • top, right, bottom, left 的配合
  13. • position • position:static; 預設 • position:absolute; 絕對定位 • position:relative;

    相對定位 • position:fixed; • top, right, bottom, left 的配合 • 在目前的位置往下移 5px position:relative; top:5px;
  14. • position • position:static; 預設 • position:absolute; 絕對定位 • position:relative;

    相對定位 • position:fixed; • top, right, bottom, left 的配合 • 在目前的位置往下移 5px position:relative; top:5px; • 整份文件中的右下角: position:absolute; right:0; bottom:0;
  15. • position • position:static; 預設 • position:absolute; 絕對定位 • position:relative;

    相對定位 • position:fixed; • top, right, bottom, left 的配合 • 在目前的位置往下移 5px position:relative; top:5px; • 整份文件中的右下角: position:absolute; right:0; bottom:0; • 可視區域的最下方(IE6不支援):
  16. 解決 IE 6,7 與其他瀏覽器 在樣式上的差異 • “bakground:gray \9”; • ⼀一般瀏覽器

    • background:blue; • IE 6 與 7 都會套用 * 開頭的 CSS Rule • *background:red; • IE 6 會套用 _ 開頭的 CSS Rule IE 7 則不理會 • _background:green;
  17. IE 6, IE7, Firefox 會有不同的底色 #article .bd { background:blue; *background:green;

    _background:red; } FF, IE 6, IE 7, Safari... IE 6, IE 7 IE 6
  18. 72px 18px background:100% 0; background:100% -18px; 18px background:0 -36px; background:0

    -54px; CSS Sprites:將多張背景合成⼀一張 http://www.lesliesommer.com/wdw07/html/images/cr_big.gif