小程序模板網(wǎng)

Flex 實(shí)現(xiàn)表格布局 (微信小程序)

發(fā)布時(shí)間:2018-04-23 12:16 所屬欄目:小程序開(kāi)發(fā)教程

微信小程序自己開(kāi)發(fā)了一套 wxml + wxss,對(duì)許多 HTML 標(biāo)簽和 CSS 屬性不支持。

不支持 table 標(biāo)簽,推薦使用 flex 布局。

自然而然的想法:flex 嵌套,效果還不錯(cuò),貼代碼如下:

 

				
  1. <view id="panel" class="flex-column">
  2. <view class="flex-cell flex-row">
  3. <text class="flex-cell flex-row">1</text>
  4. <text class="flex-cell flex-row">2</text>
  5. <text class="flex-cell flex-row">3</text>
  6. <text class="flex-cell flex-row">4</text>
  7. </view>
  8. <view class="flex-row flex-cell">
  9. <text class="flex-cell flex-row">1</text>
  10. <text class="flex-cell flex-row">2</text>
  11. <text class="flex-cell flex-row">3</text>
  12. <text class="flex-cell flex-row">4</text>
  13. </view>
  14. <view class="flex-row flex-cell">
  15. <text class="flex-cell flex-row">1</text>
  16. <text class="flex-cell flex-row">2</text>
  17. <text class="flex-cell flex-row">3</text>
  18. <text class="flex-cell flex-row">4</text>
  19. </view>
  20. <view class="flex-row flex-cell">
  21. <text class="flex-cell flex-row">1</text>
  22. <text class="flex-cell flex-row">2</text>
  23. <text class="flex-cell flex-row">3</text>
  24. <text class="flex-cell flex-row">4</text>
  25. </view>
  26. <view class="flex-row flex-cell">
  27. <text class="flex-cell flex-row">1</text>
  28. <text class="flex-cell flex-row">2</text>
  29. <text class="flex-cell flex-row">3</text>
  30. <text class="flex-cell flex-row">4</text>
  31. </view>
  32.  
  33. </view>
 

				
  1. #panel{
  2. height:65vh;
  3. background:#fff;
  4. }
  5.  
  6. #panel text{
  7. line-height: 13vh;
  8. border-right: 1rpx solid #ddd;
  9. border-bottom: 1rpx solid #ddd;
  10. }
  11.  
  12. .flex-row{
  13. display: flex;
  14. flex-direction: row;
  15. justify-content: center;
  16. align-items: center;
  17. }
  18. .flex-column{
  19. display: flex;
  20. flex-direction: column;
  21. justify-content: center;
  22. align-items: stretch;
  23. }
  24.  
  25. .flex-cell{
  26. flex: 1;
  27. }



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/23939.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢(xún):800182392 點(diǎn)擊咨詢(xún)
QQ在線咨詢(xún)