我制作了一个粘性页脚更高级别的组件,它将其他组件包装在自身内部:
页脚.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;
用法:
<Footer><Button>test</Button></Footer>
但它隐藏了页面的内容:
这看起来是一个常见的问题,所以我搜索了一下,发现 了这个问题,在哪里为粘性页脚推荐 FlexBox。但是在 这个演示 中,页脚位于页面的最底部,而我需要页脚始终显示在页面上,并且内容在上述区域内滚动(就像在 SO 聊天中一样) 。除此之外,还有一个建议是使用自定义样式表规则更改所有其他组件。是否可以仅使用页脚组件样式来实现我需要的功能,以便代码保持模块化?
原文由 Poliakoff 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是一个想法(沙盒示例链接)。
在您的页脚组件中包含一个幻影 div,它代表其他 dom 元素将尊重的页脚位置(即通过不
position: 'fixed';
影响页面流)。