今天看到一條屬性display: table; 可以在div等標簽中實現表格效果;
display: table=>相當於“table”標簽;
display: table-row=>相當於“tr”標簽;
display: table-cell=>相當於“td”標簽
一.父元素寬度固定,讓子元素平分寬度,用普通的方法設置%的時候是很煩的
這里使用display: table;表格屬性來解決:
.parent{display: table;width: 800px;}
.son{display: table-cell;
二.塊級子元素垂直居中
.parent{display: table;width: 800px;}
.son{display: table-cell;}
三.display:table使用時應注意的一些問題
1.display: table時 對應元素的padding會失效;
2.display: table-row時 對應元素的padding、margin會失效;
3..display: table-cell時 對應元素的margin會失效;
4.displaty: table-cell不要與float,position: absolute;等改變布局的屬性同時使用,作用會被破壞
四.display:table;其他值
1.table 此元素會作為塊級表單顯示=》
2.table-row-group 此元素會作為一個或多個行的分組顯示=》tbody
3.table-heightder-group 此元素會作為一個或多個行的分組顯示=》thead
3.table-footer-grounp 此元素會作為一個或多個行的分組顯示=》tfoot
4.table-column-grounp 此元素會作為一個或多個列的分組顯示=》colgroup
5.table-column 此元素會作為一個單元格列顯示=>col
6.table-caption 此元素會作為一個表格標題顯示=》caption