如何在菜单标头中固定徽章位置与蚂蚁设计反应

发布于 2025-02-13 01:23:46 字数 1354 浏览 1 评论 0原文

我试图将一个元素徽章放在我的页面中的标头菜单的右侧,但我不知道这是如何的,目前,ant Design的菜单元素将徽章推向另一个位置(贝尔图标):

代码:

const HeaderComp = (props) => {
let navigation = useNavigate()
const root= AppConfig.BucciaratiRoot.length>0 ? "/"+AppConfig.BucciaratiRoot:"/"

return (
  <Layout>
    <Header className="header" style={{position:'fixed', zIndex: 1, width:   '100%'}}>            
        <div style={{float:'left', marginRight:'5%'}}>
            <img style={{width: 120, height:31}} src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"/>
        </div>
        <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} >
            <Menu.Item key="1" onClick={()=>navigation(root)}>Home</Menu.Item>
            <Menu.Item key="3">About</Menu.Item>
        </Menu> 
        <div style={{float:'right', marginLeft:'5%'}}>
            <Badge dot>
                <BellOutlined />
            </Badge>
        </div>    
    </Header>
  </Layout>  
 )
}

该隐如何将标题菜单右侧的徽章放在徽章上?

im trying to put an element Badge to the right of header menu in my page, but I don't know how do that, currently de Menu element of ant design push to another position the badge (bell icon):
enter image description here

The code:

const HeaderComp = (props) => {
let navigation = useNavigate()
const root= AppConfig.BucciaratiRoot.length>0 ? "/"+AppConfig.BucciaratiRoot:"/"

return (
  <Layout>
    <Header className="header" style={{position:'fixed', zIndex: 1, width:   '100%'}}>            
        <div style={{float:'left', marginRight:'5%'}}>
            <img style={{width: 120, height:31}} src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"/>
        </div>
        <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} >
            <Menu.Item key="1" onClick={()=>navigation(root)}>Home</Menu.Item>
            <Menu.Item key="3">About</Menu.Item>
        </Menu> 
        <div style={{float:'right', marginLeft:'5%'}}>
            <Badge dot>
                <BellOutlined />
            </Badge>
        </div>    
    </Header>
  </Layout>  
 )
}

How cain I put the badge to the right of the header menu ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好听的两个字的网名 2025-02-20 01:23:46

您可以使用 flex 而不是 float ,但是您想在DIV中右侧的每个元素,而每个Div中的每个元素,并使用一些元素 Jusify-content:“之间的空间” flex 中的属性您可以使纳维托中的空间在divs之间留在磁带中。
在flexbox上查看更多信息

您的代码应该看起来像:

return (
<Layout>
    <Header
        className='header'
        style={{
            position: "fixed",
            zIndex: 1,
            width: "100%",

            display: "flex", // make the header flex
            justifyContent: "space-between", // put all the space between the left and right sections of the menu
        }}
    >
        <div className='header-left'>
            {/* The left side of the menu */}

            <div style={{ /* remove float */ marginRight: "5%" }}>
                <img
                    style={{ width: 120, height: 31 }}
                    src='https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png'
                />
            </div>
            <Menu
                theme='dark'
                mode='horizontal'
                defaultSelectedKeys={["1"]}
            >
                <Menu.Item key='1' onClick={() => navigation(root)}>
                    Home
                </Menu.Item>
                <Menu.Item key='3'>About</Menu.Item>
            </Menu>
        </div>

        <div className='header-right'>
            {/* The right side of the menu */}
            <div style={{ /* remove float */ marginLeft: "5%" }}>
                <Badge dot>
                    <BellOutlined />
                </Badge>
            </div>
        </div>
    </Header>
</Layout>
);

You can use flex instead of float, and then but every element you want to be at the right in a div and every element to the left in another div, and using some justify-content:"space-between" property in flex you can make the space left in the navbar to be in between those to divs.
See more on FlexBox

your code should look like:

return (
<Layout>
    <Header
        className='header'
        style={{
            position: "fixed",
            zIndex: 1,
            width: "100%",

            display: "flex", // make the header flex
            justifyContent: "space-between", // put all the space between the left and right sections of the menu
        }}
    >
        <div className='header-left'>
            {/* The left side of the menu */}

            <div style={{ /* remove float */ marginRight: "5%" }}>
                <img
                    style={{ width: 120, height: 31 }}
                    src='https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png'
                />
            </div>
            <Menu
                theme='dark'
                mode='horizontal'
                defaultSelectedKeys={["1"]}
            >
                <Menu.Item key='1' onClick={() => navigation(root)}>
                    Home
                </Menu.Item>
                <Menu.Item key='3'>About</Menu.Item>
            </Menu>
        </div>

        <div className='header-right'>
            {/* The right side of the menu */}
            <div style={{ /* remove float */ marginLeft: "5%" }}>
                <Badge dot>
                    <BellOutlined />
                </Badge>
            </div>
        </div>
    </Header>
</Layout>
);
¢蛋碎的人ぎ生 2025-02-20 01:23:46
<Layout>
    <Header
        className="header"
        style={{
            position: 'fixed',
            zIndex: 1,
            width: '100%',
            display: 'flex',
            justifyContent: 'space-between',
        }}
    >
        <div>
            <div style={{ marginRight: '5%' }}>
                <img
                    style={{ width: 120, height: 31 }}
                    src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"
                />
            </div>
            <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']}>
                <Menu.Item key="1" onClick={() => navigation(root)}>
                    Home
                </Menu.Item>
                <Menu.Item key="3">About</Menu.Item>
            </Menu>
        </div>

        <div style={{ marginLeft: '5%' }}>
            <Badge dot>
                <BellOutlined />
            </Badge>
        </div>
    </Header>
</Layout>;
<Layout>
    <Header
        className="header"
        style={{
            position: 'fixed',
            zIndex: 1,
            width: '100%',
            display: 'flex',
            justifyContent: 'space-between',
        }}
    >
        <div>
            <div style={{ marginRight: '5%' }}>
                <img
                    style={{ width: 120, height: 31 }}
                    src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"
                />
            </div>
            <Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']}>
                <Menu.Item key="1" onClick={() => navigation(root)}>
                    Home
                </Menu.Item>
                <Menu.Item key="3">About</Menu.Item>
            </Menu>
        </div>

        <div style={{ marginLeft: '5%' }}>
            <Badge dot>
                <BellOutlined />
            </Badge>
        </div>
    </Header>
</Layout>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文