Jam*_*mes 14 css reactjs material-ui
我正在为我的 React 应用程序使用 Material-UI@next。在一个特定组件中,我使用Expansion Panels显示项目列表。我还有一个简单的<Footer />组件,如下所示:
import React, { Component } from "react";
import styled from "styled-components";
import Typography from "material-ui/Typography";
const FooterContainer = styled.div`
  text-align: center;
  position: absolute;
  bottom: 0;
  width: 100% !important;
  height: 100px !important ;
  background: #6cf;
`;
class Footer extends Component {
  render() {
    return (
      <FooterContainer>
        <Typography variant="title">Footer Text</Typography>
      </FooterContainer>
    );
  }
}
export default Footer;
Run Code Online (Sandbox Code Playgroud)
这是我在<Footer />项目列表下使用的代码片段:
  render() {
    return this.props.isFetching ? (
      <Typography>Loading...</Typography>
    ) : (
      <Container>
        <StyledTitle variant="display1" gutterBottom color="secondary">
          Listings
        </StyledTitle>
        <Grid container spacing={24}>
          {this.renderListings()}
        </Grid>
        <Footer />
      </Container>
    );
  }
Run Code Online (Sandbox Code Playgroud)
, whererenderListings()只是对数组进行迭代并在扩展面板中显示结果:
...
      <Grid key={listing._id} item xs={12} sm={12} lg={12}>
        <StyledExpansionPanel>
          <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
            <ExpansionPanelColumn>
              <Typography>{listing.name}</Typography>
            </ExpansionPanelColumn>
          </ExpansionPanelSummary>
          <Divider />
          <ExpansionPanelDetails>
            <Typography>Notes: {listing.notes}</Typography>
          </ExpansionPanelDetails>
          <Divider />
        </StyledExpansionPanel>
      </Grid>
...
Run Code Online (Sandbox Code Playgroud)
问题是,当扩展面板关闭时,页脚显示正常,但是当扩展面板打开时,它们位于页脚下方,页脚不再位于页面底部。
Jam*_*mes 16
我通过使用解决了这个问题flex。简而言之,我需要做的就是<Container />按如下方式更改组件样式:
export const Container = styled.div`
  display: flex;
  min-height: 100vh;
  flex-direction: column;
`;
Run Code Online (Sandbox Code Playgroud)
当我将垂直部分包装在一个 flex 容器中并选择要扩展的部分时,它们会自动占用容器中的所有可用空间。
Kar*_*yan 14
footer {
  margin-top:calc(5% + 60px);
  bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
这对我来说很好用
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           44510 次  |  
        
|   最近记录:  |