Weex默認爲flex佈局且只支持flex佈局。使用flex佈局實現footer固定在底部。這裏參考菜鳥教程上的文章Flex 佈局語法教程來實現。css
<template> <div class="wrapper"> <div class="tab-container"> <text>main</text> </div> <div class="footer"> <text>footer</text> </div> </div> </template> <style scoped> .wrapper { background-color: azure; flex-direction: column; width: 750px; } .tab-container { background-color: beige; width: 750px; flex: 1; } .footer { background-color: rgba(255, 255, 0, 1); width: 750px; height: 100px; flex: 0; border-radius: 10px 10px 0 0; padding: 5px 5px 5px 5px; } </style>
這裏的重點在於wrapper中flex-direction:column
設置flex排布方向。主頁面tab-container
中設置flex:1
且footer
中設置flex:0
來使得tab-container
能夠自動填滿空白而footer
固定大小。
這裏面踩的坑主要有:html
div.footer
這種選擇器flex: <flex-grow> | <flex-shrink> | <'flex-basis>
的簡寫。且不支持flex-shrink
和 flex-basis
屬性。width:100%
這樣設置寬度只在web頁面上有效,而在Android端無效。weex默認使用750px做爲屏幕的寬度,任何大小的設置都按750px來等比換算。例如,width:50%
等價於width:375px
。weex對css的支持有限,本來在web端適用的方案在weex中不必定適用。對weex文檔熟悉的話能夠必定程度上避免不少問題。所以出現問題後優先查閱其文檔。web