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