gpt4 book ai didi

html - 100% 高度不适用于抽屉,Material Design React

转载 作者:技术小花猫 更新时间:2023-10-29 11:45:15 25 4
gpt4 key购买 nike

我正在使用 React Material UI 中的响应式抽屉([文档][1])

我正在尝试更改它,以便抽屉的高度始终为 100%。为此,我尝试更改当前设置为 430 的根类的高度。但是,当我将其设置为百分比时,它只是默认为可能的最小高度。

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from 'material-ui/styles';
import Drawer from 'material-ui/Drawer';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import List from 'material-ui/List';
import { MenuItem } from 'material-ui/Menu';
import TextField from 'material-ui/TextField';
import Typography from 'material-ui/Typography';
import Divider from 'material-ui/Divider';
import { mailFolderListItems, otherMailFolderListItems } from './tileData';

const drawerWidth = 240;

const styles = theme => ({
root: {
width: '100%',
height: 430,
marginTop: theme.spacing.unit * 3,
zIndex: 1,
overflow: 'hidden',
},
appFrame: {
position: 'relative',
display: 'flex',
width: '100%',
height: '100%',
},
appBar: {
position: 'absolute',
width: `calc(100% - ${drawerWidth}px)`,
},
'appBar-left': {
marginLeft: drawerWidth,
},
'appBar-right': {
marginRight: drawerWidth,
},
drawerPaper: {
position: 'relative',
height: '100%',
width: drawerWidth,
},
drawerHeader: theme.mixins.toolbar,
content: {
backgroundColor: theme.palette.background.default,
width: '100%',
padding: theme.spacing.unit * 3,
height: 'calc(100% - 56px)',
marginTop: 56,
[theme.breakpoints.up('sm')]: {
height: 'calc(100% - 64px)',
marginTop: 64,
},
},
});

class PermanentDrawer extends React.Component {
state = {
anchor: 'left',
};

handleChange = event => {
this.setState({
anchor: event.target.value,
});
};

render() {
const { classes } = this.props;
const { anchor } = this.state;

const drawer = (
<Drawer
type="permanent"
classes={{
paper: classes.drawerPaper,
}}
anchor={anchor}
>
<div className={classes.drawerHeader} />
<Divider />
<List>{mailFolderListItems}</List>
<Divider />
<List>{otherMailFolderListItems}</List>
</Drawer>
);

let before = null;
let after = null;

if (anchor === 'left') {
before = drawer;
} else {
after = drawer;
}

return (
<div className={classes.root}>
<TextField
id="permanent-anchor"
select
label="Anchor"
value={anchor}
onChange={this.handleChange}
margin="normal"
>
<MenuItem value="left">left</MenuItem>
<MenuItem value="right">right</MenuItem>
</TextField>
<div className={classes.appFrame}>
<AppBar className={classNames(classes.appBar, classes[`appBar-${anchor}`])}>
<Toolbar>
<Typography type="title" color="inherit" noWrap>
Permanent drawer
</Typography>
</Toolbar>
</AppBar>
{before}
<main className={classes.content}>
<Typography type="body1">
{'You think water moves fast? You should see ice.'}
</Typography>
</main>
{after}
</div>
</div>
);
}
}

PermanentDrawer.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(PermanentDrawer);


[1]: https://material-ui-next.com/demos/drawers/

最佳答案

您可能已经解决了这个问题,但我遇到了同样的问题。我有一种预感,高度问题出在 #root id 之内。所以我将我的根 div id 更改为另一个(我使用了 application)并像这样设置高度:

appFrame: {
...
height: '100vh',
}

它奏效了。所以一个疯狂的猜测是他们已经为#root id 定义了一个样式。我会在有时间的时候尝试找出这是否正确

关于html - 100% 高度不适用于抽屉,Material Design React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com