Web前端面試指導(十五):CSS樣式-display有哪些作用?

題目點評

其實就是要你說清楚該屬性有哪些值,每個值都有什麼作用,這個題目可以答得很簡單,但要答全也並非是一件容易的事情。

元素默認的display值的情況如下這個一般很少人注意這一點


  •  block(塊級元素)


 <div>、<p> <ul> <ol> <form> ……


  •  inline(內聯元素)


 <span> <a> <img> <input> <select> <label> ……


  •  list-item(項目列表)


 <li>


  •  none(不顯示)


 <head>(頭部元素都是) <title> <br> <thead> <tbody> <tfoot> 

常見的屬性值(屬性值太多,只要說常用的就好)

  •  none:元素隱藏

  •  block:塊級元素

  •  inline-block:內聯塊級元素

  •  list-item:列表項目

  •  表格系列方面的顯示

  •  table

  •  table-row

      示例:div+css製作表格

      html代碼

[html] view plain copy 在CODE上查看代碼片派生到我的代碼片

  1. <div class="table">  

  2.     <h2 class="table-caption">花名冊:</h2>  

  3.     <div class="table-column-group">  

  4.         <div class="table-column"></div>  

  5.         <div class="table-column"></div>  

  6.         <div class="table-column"></div>  

  7.     </div>  

  8.     <div class="table-header-group">  

  9.         <ul class="table-row">  

  10.             <li class="table-cell">序號</li>  

  11.             <li class="table-cell">姓名</li>  

  12.             <li class="table-cell">年齡</li>  

  13.         </ul>  

  14.     </div>  

  15.     <div class="table-footer-group">  

  16.         <ul class="table-row">  

  17.             <li class="table-cell">footer</li>  

  18.             <li class="table-cell">footer</li>  

  19.             <li class="table-cell">footer</li>  

  20.         </ul>  

  21.     </div>  

  22.     <div class="table-row-group">  

  23.         <ul class="table-row">  

  24.             <li class="table-cell">1</li>  

  25.             <li class="table-cell">John</li>  

  26.             <li class="table-cell">19</li>  

  27.         </ul>  

  28.         <ul class="table-row">  

  29.             <li class="table-cell">2</li>  

  30.             <li class="table-cell">Mark</li>  

  31.             <li class="table-cell">21</li>  

  32.         </ul>  

  33.         <ul class="table-row">  

  34.             <li class="table-cell">3</li>  

  35.             <li class="table-cell">Kate</li>  

  36.             <li class="table-cell">26</li>  

  37.         </ul>  

  38.     </div>  

  39. </div>  

CSS代碼

[html] view plain copy 在CODE上查看代碼片派生到我的代碼片

  1. ul{margin:0;padding:0;list-style:none;}  

  2. .table{display:table;border-collapse:collapse;border:1px solid #ccc;}  

  3. .table-caption{display:table-caption;margin:0;padding:0;font-size:16px;}  

  4. .table-column-group{display:table-column-group;}  

  5. .table-column{display:table-column;width:100px;}  

  6. .table-row-group{display:table-row-group;}  

  7. .table-row{display:table-row;}  

  8. .table-row-group .table-row:hover,.table-footer-group .table-row:hover{background:#f6f6f6;}  

  9. .table-cell{display:table-cell;padding:0 5px;border:1px solid #ccc;}  

  10. .table-header-group{display:table-header-group;background:#eee;font-weight:bold;}  

  11. .table-footer-group{display:table-footer-group;}  


效果圖

加分項

  •  行級元素浮動之後,display爲block。

  • flex(彈性盒子)
     不過要結合相關的屬性一起,flex-flow和flex。在響應式開發中flex非常有用。

        行式佈局 flex-flow: row;

html代碼

[html] view plain copy 在CODE上查看代碼片派生到我的代碼片

  1. <div class="div-flex-box">  

  2.     <div class="flex-1" ></div>  

  3.     <div class="flex-2"></div>  

  4.     <div class="flex-3"></div>  

  5. </div>  


css代碼

[css] view plain copy 在CODE上查看代碼片派生到我的代碼片

  1. .div-flex-box {  

  2.     display: flex;  

  3.     flex-flow: row; /*行式佈局*/  

  4. }  

  5. .flex-1{  

  6.     flex:1;  /*佔1份,共4份*/  

  7.     height60px;  

  8.     background-color: aquamarine;  

  9. }  

  10. .flex-2{  

  11.     flex:2/*佔2份,共4份*/  

  12.     height60px;  

  13.     background-color: chocolate;  

  14. }  

  15. .flex-3{  

  16.     flex:1/*佔1份,共4份*/  

  17.     height60px;  

  18.    background-color: darkcyan;  

  19. }  


效果圖




  

-------------------------------------------------------------------------------------------


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章