div对齐不适用于带有菜单的标题

塞布

我尝试正确调整菜单,但无法正常工作。这样做的方式是,当您到达我的网站但未登录时,将显示以下标题:

在此处输入图片说明

用户登录后,login/register将由向下滚动菜单代替,该菜单由单击头像触发。向下滚动正常,但菜单的渲染未对齐,如下所示:

在此处输入图片说明

首先,我无法使头像和菜单正确对齐。

下面是代码:

const fakeName = "First Last";
const isGuest = false;

const StyledProfileMenu = withStyles({
    paper: {
      border: '1px none',
      borderRadius: "21px",
      boxShadow: "0px 8px 18px 0 rgba(0,0,0,0.14)",
    },
  })((props) => (
    <Menu
      elevation={0}
      getContentAnchorEl={null}
      anchorOrigin={{
        vertical: 'bottom',
        horizontal: 'left',
      }}
      transformOrigin={{
        vertical: 'top',
        horizontal: 'center',
      }}
      {...props}
    />
  ));

  const StyledProfileMenuItem = withStyles((theme) => ({
    root: {
        margin: "2px 30px 1px 10px",
        fontFamily: "Source Sans Pro",
        fontSize: "",
        '&:hover': {
            backgroundColor: "#ffffff",
            color: '#ff7255'},

        '&:focus': {
            backgroundColor: "#ffffff",
            color: '#ff7255'},
    },
  }))(MenuItem);


const useStyles = makeStyles(theme => ({
    root: {
      boxShadow: "none",
      backgroundColor:  "#ffffff",
      marginTop: theme.spacing(3)
    },
    logo: {
        width:"214px",
        height:"28px",
        marginLeft: theme.spacing(20),
        marginRight: theme.spacing(3)

    },
    search: {
        position: 'relative',
        borderRadius: "21px",
        backgroundColor: "#f4f7f8",
        marginRight: theme.spacing(2),
        marginLeft: theme.spacing(3),
        width: "467px",
        height: "40px",
       // [theme.breakpoints.up('sm')]: {
       //   marginLeft: theme.spacing(3),
      //    width: 'auto',
       // },
      },
      searchIcon: {
        padding: theme.spacing(1, 2),
        height: '18px',
        width: '18px',
        position: 'absolute',
        pointerEvents: 'none',
        alignItems: 'center',
        justifyContent: 'center',
        color: "#cecece"
      },
      inputRoot: {
        color: "#cecece",
        fontFamily: "Source Sans Pro",
        fontSize: "18px"
      },
      inputInput: {
        paddingLeft: `calc(1em + ${theme.spacing(4)}px)`,
        width: "467px",
      //  [theme.breakpoints.up('md')]: {
      //    width: '20ch',
      //  },
      },
      menu: {
        display: "flex",
        marginLeft: theme.spacing(2),
        margin: "auto",
      },
      menuItem: {
        color: "#cecece",
        fontSize: "20px",
        fontFamily: "Fredoka One",
        fontWeight: "bold",
        '&:hover': {
            backgroundColor: "#ffffff",
            color: '#ff7255'},
        '&:focus': {
            backgroundColor: "#ffffff",
            color: '#ff7255'},
        marginRight: theme.spacing(3),
        marginLeft: theme.spacing(3),
      },
      userName: {
          fontFamily: "Source Sans Pro",
          fontWeight: "Bold",
          borderBottom: '3px solid #ff7255',
          textAlign: "center",
          margin: "2px 10px 2px 10px",
          paddingBottom: "2px"
      }
  }));




function Header(){

    let loginOrProfile;

    const styles = useStyles();

    const [anchorEl, setAnchorEl] = React.useState(null);

    const handleClick = (event) => {
        setAnchorEl(event.currentTarget);
    };

    const handleClose = () => {
        setAnchorEl(null);
    };

    const profileMenu = 
        <div>
        <IconButton
            aria-controls="customized-menu"
            aria-haspopup="true"
            variant="contained"
            color="primary"
            onClick={handleClick}>
            <Avatar alt="Avatar" src={DefaultAvatar} /> 
            <ArrowDropDownIcon style={{ color: "#ff7255" }}/>       
        </IconButton>
        <StyledProfileMenu
            id="customized-menu"
            anchorEl={anchorEl}
            keepMounted
            open={Boolean(anchorEl)}
            onClose={handleClose}>
            <p className={styles.userName}> {fakeName} </p>
            <StyledProfileMenuItem>
            <ListItemText primary={TextContents.MenuProfile} />
            </StyledProfileMenuItem>
            <StyledProfileMenuItem>
            <ListItemText primary={TextContents.MenuMessages} />
            </StyledProfileMenuItem>
            <StyledProfileMenuItem>
            <ListItemText primary={TextContents.MenuSettings} />
            </StyledProfileMenuItem>
            <StyledProfileMenuItem>
            <ListItemText primary={TextContents.MenuLogout} />
            </StyledProfileMenuItem>
        </StyledProfileMenu>
        </div>;

    const loginMenu = 
        <Typography className={styles.menuItem}> {TextContents.MenuLoginRegister} </Typography>;


    if(isGuest){
        loginOrProfile = loginMenu;
    } else {
        loginOrProfile = profileMenu;
    }

    return (
        <div className={styles.root}>
            <AppBar position="static" className={styles.root}>
                <Toolbar>
                    <img src={VillageLogo} alt="logo" className={styles.logo}/>
                    <div className={styles.search}>
                        <div className={styles.searchIcon}>
                            <SearchIcon />
                        </div>
                        <InputBase
                            placeholder={TextContents.SearchPlaceHolder}
                            classes={{
                                root: styles.inputRoot,
                                input: styles.inputInput,
                            }}
                            inputProps={{ 'aria-label': 'search' }}
                        />
                    </div>
                    <div className={styles.menu}>
                        <Typography className={styles.menuItem}> {TextContents.MenuDiscover} </Typography>
                        <Typography className={styles.menuItem}> {TextContents.MenuCreate} </Typography>
                        <Typography className={styles.menuItem}> {TextContents.MenuHiW} </Typography>
                        {isGuest && loginMenu}
                        {!isGuest && profileMenu}
                    </div>
                </Toolbar>

            </AppBar>
        </div>
    );
}



export default Header

如果有人对如何正确调整对齐有任何想法,我将非常高兴

红男爵

尝试这个:

display: flex;
align-items: center;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

带有标题下拉菜单的导航适用于世博小吃,但不适用于 CLI

来自分类Dev

“位置:固定”不适用于标题菜单

来自分类Dev

下拉菜单不适用于带有 sass 的 bootstrap4

来自分类Dev

垂直对齐不适用于div

来自分类Dev

CSS宽度和高度不适用于带有display:inline的div

来自分类Dev

CSS宽度和高度不适用于带有display:inline的div

来自分类Dev

CSS:100%的高度不适用于带有display:table的div

来自分类Dev

textarea不适用于带有值的文档加载

来自分类Dev

npm命令不适用于带有zsh的WSL

来自分类Dev

文字对齐不适用于Chrome

来自分类Dev

图例标题不适用于 MatLab

来自分类Dev

垂直对齐中心不适用于 div 文本对齐

来自分类Dev

背景颜色不适用于所有div

来自分类Dev

.next()不适用于所有div

来自分类Dev

背景颜色不适用于所有div

来自分类Dev

溢出隐藏不适用于“垂直对齐的底部” - 绝对定位的外部 div 中的 div

来自分类Dev

文本对齐:对齐;不适用于wkhtmltopdf

来自分类Dev

垂直对齐包装器div不适用于多行文本

来自分类Dev

用于EditText的ActionNext不适用于对齐/快速滚动

来自分类Dev

悬停不适用于动画div

来自分类Dev

翻译属性不适用于div

来自分类Dev

slideToggle不适用于多个div

来自分类Dev

不适用于CSS的div

来自分类Dev

单击不适用于内部div

来自分类Dev

ngClick不适用于div元素

来自分类Dev

css 属性不适用于 div

来自分类Dev

css 不适用于 div

来自分类Dev

CSS不适用于div元素

来自分类Dev

jquery 抖动不适用于 div