CSS 應用技巧

發表時間: 2010-11-13 20:44:35
一劃 @ 61.56.133.15
  1. 將依比例設定的 div 區塊置中

    margin-left: auto;
    margin-right: auto;
  2. 在設置完區塊 float 之後,後面的排版亂掉 在 css 裡加入以下兩行,然後在 html 文件在設置完 float 的區塊後加上 <p class="clear"></p>

    .clear {zoom:1; clear:both;}
    .clear:after {content:''; display:block; clear:both; visibility:hidden; height:0;}
  3. 區塊並排,並非一定要用 float,可設 display: inline-block 來完成。

  4. <table> 改用 <div> for example html:

    &lt;div id=&quot;data_grid&quot;&gt;
           &lt;div id=&quot;subtitle&quot;&gt;
               &lt;span class=&quot;st_date&quot;&gt;日期&lt;/span&gt;
               &lt;span class=&quot;st_subject&quot;&gt;標題&lt;/span&gt;
               &lt;span class=&quot;st_poster&quot;&gt;發文者&lt;/span&gt;
               &lt;span class=&quot;st_number&quot;&gt;篇數&lt;/span&gt;
               &lt;span class=&quot;st_view&quot;&gt;查閱數&lt;/span&gt;
           &lt;/div&gt;
           &lt;div class=&quot;article_list&quot;&gt;
               &lt;span class=&quot;st_date&quot;&gt;2010-09-05&lt;/span&gt;
               &lt;span class=&quot;st_subject&quot;&gt;Fedora 13 筆記 (Virtual Box)&lt;/span&gt;
               &lt;span class=&quot;st_poster&quot;&gt;一劃&lt;/span&gt;
               &lt;span class=&quot;st_number&quot;&gt;3&lt;/span&gt;
               &lt;span class=&quot;st_view&quot;&gt;266&lt;/span&gt;
           &lt;/div&gt;
    &lt;/div&gt;

    css:

    
    #data_grid {
    font-weight: normal;
    display: table;
    font-size: 14px;
    margin: 0px;
    padding: 0px;
    width: 100%;
    border-left: solid 1px #BB8800;
    border-top: solid 1px #BB8800;
    }
    #subtitle {
    display: table-row;
    background-color: #BB8800;
    color: #FFFFFF;
    margin: 0px;
    padding: 0px;
    }

.article_list { display: table-row; background-color: #ffffff; color: #000000; margin: 0px; padding: 0px; }

.st_date { display: table-cell; border-right: solid 1px #BB8800; border-bottom: solid 1px #BB8800; margin: 0px; padding: 3px; width: 15%; } .st_subject { display: table-cell; border-right: solid 1px #BB8800; border-bottom: solid 1px #BB8800; margin: 0px; padding: 3px; width: 50%; } .st_poster { display: table-cell; border-right: solid 1px #BB8800; border-bottom: solid 1px #BB8800; margin: 0px; padding: 3px; width: 15%; } .st_number { display: table-cell; border-right: solid 1px #BB8800; border-bottom: solid 1px #BB8800; margin: 0px; padding: 3px; width: 10%; } .st_view { display: table-cell; border-right: solid 1px #BB8800; border-bottom: solid 1px #BB8800; margin: 0px; padding: 3px; width: 20%; }



以後有新的再往下加下去

回應文章