【发布时间】:2020-07-10 08:12:59
【问题描述】:
我想将菜单组件中的子菜单项与其他菜单项对齐。到目前为止,我已经尝试过 style={{float:right}},但是它没有对齐,我在其他菜单项和我的菜单项之间放置了多个空按钮以将菜单项向右推,但它一直在波动。我希望这个子菜单位于水平菜单的右侧,我正在使用来自“antd”的 ReactJS 和菜单组件:“^2.13.6”。 我的代码是:
return (
<Menu mode='horizontal'>
<Menu.Item >
<Link to='/'>
<Icon type='home' /><text style={{fontWeight: "bold"}}> Home</text>
</Link>
</Menu.Item>
<Menu.Item>
<Link to='popular'>
<Icon type='heart-o' /> <text style={{fontWeight: "bold"}}>Popular</text>
</Link>
</Menu.Item>
<Menu.Item>
<Link to='upcoming'>
<Icon type='like-o' /> <text style={{fontWeight: "bold"}}>Up Coming</text>
</Link>
</Menu.Item>
<Menu.Item>
<Link to='nowplaying'>
<Icon type='rocket' /> <text style={{fontWeight: "bold"}}>Now Playing</text>
</Link>
</Menu.Item>
<SubMenu style={{float:'right'}} title={ <text style={{fontWeight: "bold"}}>Diana</text>}>
<Menu.Item key="setting:1">Get Recs</Menu.Item>
<Menu.Item key="setting:2">Dashboard</Menu.Item>
<Menu.Item key="setting:3" onClick={() => this.logout()}>
<Link to='/' onClick={() => this.logout()}>
<Icon onClick={() => this.logout()}/> <text style={{fontWeight: "bold"}}>Logout</text>
</Link>
</Menu.Item>
</SubMenu>
</Menu>
)
这是我在运行代码时得到的以及我想要得到的图片 https://imgur.com/a/pYw97TV
【问题讨论】: