DedeCMS修改模板默認CSS文件分析全過程_DedeCms教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!
      給大家講一下織夢DedeCMS修改模板默認CSS文件分析全過程,僅供學習參考!

      首先,打開后臺——模板——默認模板管理——index.htm.
      看到有一句,<link href="{dede:global.cfg_templeturl/}/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" />說明,我們模板是根據這個CSS來布局網頁的,于是我們就打開網站目錄下面的templets\style\dedecms.css.然后來分析一下CSS的構成。
      我們根據主頁的調用,來研究CSS這樣容易理解。我們打開主頁模板,找到:
      <div class="w960 center clear mt1">/*這句是控制除了網站頭部和友情鏈接的所有結構樣式*/
      那么 w960 center clear mt1 都定義了什么呢?我們打開DEDECMS.CSS 找打相關的定義。
      1. /*---------- stock ---------*/  
      2. .center{  
      3.     margin:0px auto; 定義了CSS模塊的邊緣位置都是0,也就是這個center的層 距離上右下左都是0px; 
      4. }  
      5. .w960{  
      6.     width:960px; 定義了整體的寬度為960px; 
      7.     /*position:relative;*/  
      8. }  
      9. .pright .infos_userinfo {  
      10.     margin-bottom: 0px; 定義了首頁右部下的 互動中心的下面邊緣為0px; 
      11. }  
      12. .mt1{/* ( margin-top * 1 ) */  
      13.     margin-top:8px; 定義了mt1的頂部邊緣為8px; 
      14. }  
      15. .pright .mt1{  
      16.     margin-top:0px; 定義了pright 下面的mt1頂部邊緣為0px; 
      17. }  
      18. .mt2{/* ( margin-top * 2 ) */  
      19.     margin-top:16px; 頂部邊緣為16px; 
      20. }  
      21. .clear{  
      22.     overflow:hidden; 如果clear層里面的內容超出了 層的范圍 就隱藏起來。 
      23. }  
      24.      
      25.          <div class="pleft">這個pleft 的定義 沒有在dedecms.css 中,但是我們會發現一句話 
      26. @import url("layout.css"); 
      27. @import url("page.css"); 
      28. 這說明,在dedecms.css 中引用了 page.css 和layout.css 這兩個樣式表,于是我們就在page.css 中找到了pleft 的定義 
      29. .pleft{ 
      30. width:712px;定義了寬度 
      31. float:left;該層向左浮動 
      32. overflow:hidden;超出范圍則隱藏 
      33.     <div class="bignews"> 
      34.      在該層下面調用的是新聞頭條的內容,看看它的css 
      35. .index .bignews{ 
      36. width:424px; 
      37. height:400px; 
      38. float:right; 向右浮動 
      39. border:1px solid #DFF2F5;表示邊框線用 #dff2f5的實體顏色填充 
      40. background:url(../images/headbg-top.gif) repeat-x;背景圖片為 headbg-top.gif   并且橫向平鋪 
      41. overflow:hidden;超出則隱藏。 
      所以,我們看到頭條的這部分是在flash幻燈片右邊顯示,并且加上了淺藍色的邊框線。
      1. <!--頭條--> 
      2.         <div class="onenews">       再來看看 onenews是如何定義的。 
      3.         .index .bignews .onenews{ 
      4. margin:0 3px 0 3px; 左右外邊距分別空3個像素 
      5. padding:7px 6px;上左內邊距分別空7,6個像素 
      6. border-bottom:1px dashed #EBEBEB;下邊框加一個 #ebebeb的虛線 
      7. 所以我們看見頭條的文章左右都有一定的距離,并且下面還有一個虛線顯示        
      8. </div> 
      9.       <!-- /onenews --> 
      10.           這個下面調用的是以往的頭條,默認的有4篇文章,調用了d1 d1arc 2個css 
      11. .index .bignews div.d1{ 
      12. padding:6px 10px; 
      13. clear:both;這句話是清除浮動,如果不加它,大家可以試試看,是不是 d1 這個層就跑到 頭條的右邊了。 
      14. width:406px; 
      15. overflow:hidden; 
      16. .index .bignews div.d1arc{ 
      17. margin-right:12px; 
      18. width:190px; 
      19. float:left;因為此時要調用4篇文章,改文章是2*2排列的,如果不加這個屬性,新聞就應該垂直排列了(因為你剛才用clear:both 清除浮動啦),大家試試看是不是這樣的。 
      20. height:24px; 
      21. line-height:24px;行間距,即字體最底端與字體內部頂端之間的距離 
      22. overflow:hidden; 
      23.       <!--/頭條--> 
      <div class='newarticle'>最新文章</div>
      下面看看 newarticle 這個css吧,還是拿快學網的首頁舉例子,上面的這句是用來顯示 “最近更新”那幾個綠顏色字的,看看它是怎么定義的。    
      1.  .index .bignews div.newarticle{ 
      2. height:24px; 高度 
      3. background:url(../images/new-article.gif) 8px 3px no-repeat;背景圖片在x軸8px 和y軸3px出出現 
      4. font-size:0px; 
      5. color:#fff; 
      6. }    所以,我們能看到那個 最近更新 并且還有一個橫條,其實它是個圖片,大家右鍵圖片另存為看看就知道了 
      7. <ul class="c2 ico1"> 
      8.                 這里面調用了 c2 和ico1 兩個 css 
      9. .index .bignews ul.c2{ 
      10. width:416px; 
      11. padding:0px 4px 0px; 內邊距為 上0 右4下0 
      12. clear:both;清除浮動 和上面的意思一樣 
      13. overflow:hidden; 
      14. ico1 這個css 在layout.css 中了。 
      15. .ico1 li{ 
      16. padding-left:16px; 指的是 新聞列表左內邊距為16px 
      17. background:url(../images/ico-1.gif) 7px 11px no-repeat; 背景在7px,11px 處出現,所以我們看到最新文章的列表左邊都有一個小黑點,這個小黑點就是 ico-1.gif 
      18.              </ul> 
      19.            </div> 
      20.     <!-- /bignews --> 到此,中部的頭條新聞和最近更新已經分析完了。 
      21.     <div class="flashnews"> 
      22.            看看flash的 css 定義 
      23. .index .flashnews{ 
      24. width:280px; 
      25. height:192px; 
      26. overflow:hidden; 
      27. float:left;這句決定了,flash 的新聞列表在 頭條的左邊顯示。如果你把bignews 和flashnews 的float 屬性互換一下應該是上面結果呢?大家試試看。 
      28.        </div> 
      29.     <!-- /flashnews --> 
      30.     <div class="latestnews">這邊是特別推薦調用的樣式,還是來看看css 
      31. .index .latestnews{ 
      32. width:280px; 
      33. height:200px; 
      34. margin-top:8px; 
      35. float:left; 
      36. .index .latestnews dl dd{ 
      37. padding:2px 5px; 
      38. .index .latestnews ul a{ 
      39. color:#555; 
      40. } 這里面就不用解釋了吧,可以和上面的對照一下就能明白上面意思了。關鍵dl dt dd 要弄明白是什么意思。 
      希望對你有幫助。

      查看更多 DedeCms教程  織夢模板  織夢DedeCms視頻教程  織夢dedecms專題

      來源:模板無憂//所屬分類:DedeCms教程/更新時間:2020-04-21
      相關DedeCms教程