我制作了一个粘性页脚的高级组件,它将其他组件封装在自己的内部:
Footer.js
//this is a higher-order component that wraps other components placing them in footer
var style = {
backgroundColor: "#F8F8F8",
borderTop: "1px solid #E7E7E7",
textAlign: "center",
padding: "20px",
position: "fixed",
left: "0",
bottom: "0",
height: "60px",
width: "100%",
};
const Footer = React.createClass({
render: function() {
return (
<div style={style}>
{this.props.children}
</div>
);
}
});
export default Footer;
Usage:
<Footer><Button>test</Button></Footer>
但它隐藏了页面的内容:
这看起来像是一个常见的问题,所以我搜索了一下,找到了this issue,其中FlexBox推荐用于粘性页脚.但在this demo页,页脚位于页面的最底部,虽然我需要页脚始终显示在页面上,并且在上面的区域内滚动内容(如SO chat)中).除此之外,还有一个建议是使用自定义样式表规则更改所有其他组件.是否可以仅使用页脚组件的样式来实现我需要的功能,以便代码保持模块化?