可以在蚂蚁设计中更改SIDE的范围

发布于 2025-01-25 05:53:40 字数 3852 浏览 3 评论 0原文

我尝试添加.ant-layout-sider {width:500px}在app.css中,我尝试给sider component a className anding width:500px < /代码>到该课程,但没有运气。

这是我的组件

import React from 'react'
import { Image, Layout, Menu } from 'antd';
import {
  MenuUnfoldOutlined,
  MenuFoldOutlined,
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
} from '@ant-design/icons';

const { Header, Sider, Content } = Layout;

class AdminPage extends React.Component {
  state = {
    collapsed: false,
  };

  toggle = () => {
    this.setState({
      collapsed: !this.state.collapsed,
    });
  };

  render() {
    return (
      <Layout className="full-screen">
        <Sider className='light-bg' trigger={null} collapsible collapsed={this.state.collapsed}>
            <div className='logo'>
                <Image src='./logo.png' />
            </div>
            <Menu
                className='menu-fix'
                theme="light"
                mode="inline"
                defaultSelectedKeys={['1']}
                items={[
                {
                    key: '1',
                    icon: <UserOutlined />,
                    label: 'Dashboard',
                },
                {
                    key: '2',
                    icon: <VideoCameraOutlined />,
                    label: 'Search Job',
                },
                {
                    key: '3',
                    icon: <UploadOutlined />,
                    label: 'Application',
                },
                {
                    key: '4',
                    icon: <UploadOutlined />,
                    label: 'Message',
                },
                {
                    key: '5',
                    icon: <UploadOutlined />,
                    label: 'Statistics',
                },
                ]}
            />
        </Sider>
        <Layout className="site-layout">
          <Header className="site-layout-background" style={{ padding: 0 }}>
            {React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
              className: 'trigger',
              onClick: this.toggle,
            })}
          </Header>
          <Content
            className="site-layout-background"
            style={{
              margin: '24px 16px',
              padding: 24,
              minHeight: 280,
            }}
          >
            Content
          </Content>
        </Layout>
      </Layout>
    );
  }
}

export default AdminPage;

,这是我的app.css

.trigger {
    padding: 0 24px;
    font-size: 18px;
    line-height: 64px;
    cursor: pointer;
    transition: color 0.3s;
  }
  
.trigger:hover {
    color: #1890ff;
  }

.light-bg {
    background-color: #fff;
    width: 500px;
}

.menu-fix span{
    margin-left: 15px;
    margin-right: 9px;
}

.ant-menu > .ant-menu-item:hover,
.ant-menu > .ant-menu-submenu:hover,
.ant-menu > .ant-menu-item-active,
.ant-menu > .ant-menu-submenu-active,
.ant-menu > .ant-menu-item-open,
.ant-menu > .ant-menu-submenu-open,
.ant-menu > .ant-menu-item-selected,
.ant-menu > .ant-menu-submenu-selected {
  color: #003CFF;
  font-weight: bold;
}

.ant-menu-vertical .ant-menu-item::after,
.ant-menu-vertical-left .ant-menu-item::after,
.ant-menu-vertical-right .ant-menu-item::after,
.ant-menu-inline .ant-menu-item::after {
  border-right: 6px solid #003CFF;
  border-radius: 4px;
}

.ant-menu > .ant-menu-item:not(.ant-menu-item-selected) {
    color:rgba(0, 0, 0, 0.4);
}

.logo {
    margin:16px;
}

.site-layout .site-layout-background {
background: #fff;
}

.full-screen {
    min-height: 100vh;
}

。有什么想法如何更改SIDE组件的宽度?

I tried adding .ant-layout-sider { width:500px } in App.css, I tried giving the Sider component a className and adding width: 500px to that class but no luck.

Here is my component

import React from 'react'
import { Image, Layout, Menu } from 'antd';
import {
  MenuUnfoldOutlined,
  MenuFoldOutlined,
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
} from '@ant-design/icons';

const { Header, Sider, Content } = Layout;

class AdminPage extends React.Component {
  state = {
    collapsed: false,
  };

  toggle = () => {
    this.setState({
      collapsed: !this.state.collapsed,
    });
  };

  render() {
    return (
      <Layout className="full-screen">
        <Sider className='light-bg' trigger={null} collapsible collapsed={this.state.collapsed}>
            <div className='logo'>
                <Image src='./logo.png' />
            </div>
            <Menu
                className='menu-fix'
                theme="light"
                mode="inline"
                defaultSelectedKeys={['1']}
                items={[
                {
                    key: '1',
                    icon: <UserOutlined />,
                    label: 'Dashboard',
                },
                {
                    key: '2',
                    icon: <VideoCameraOutlined />,
                    label: 'Search Job',
                },
                {
                    key: '3',
                    icon: <UploadOutlined />,
                    label: 'Application',
                },
                {
                    key: '4',
                    icon: <UploadOutlined />,
                    label: 'Message',
                },
                {
                    key: '5',
                    icon: <UploadOutlined />,
                    label: 'Statistics',
                },
                ]}
            />
        </Sider>
        <Layout className="site-layout">
          <Header className="site-layout-background" style={{ padding: 0 }}>
            {React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
              className: 'trigger',
              onClick: this.toggle,
            })}
          </Header>
          <Content
            className="site-layout-background"
            style={{
              margin: '24px 16px',
              padding: 24,
              minHeight: 280,
            }}
          >
            Content
          </Content>
        </Layout>
      </Layout>
    );
  }
}

export default AdminPage;

Here is my App.css

.trigger {
    padding: 0 24px;
    font-size: 18px;
    line-height: 64px;
    cursor: pointer;
    transition: color 0.3s;
  }
  
.trigger:hover {
    color: #1890ff;
  }

.light-bg {
    background-color: #fff;
    width: 500px;
}

.menu-fix span{
    margin-left: 15px;
    margin-right: 9px;
}

.ant-menu > .ant-menu-item:hover,
.ant-menu > .ant-menu-submenu:hover,
.ant-menu > .ant-menu-item-active,
.ant-menu > .ant-menu-submenu-active,
.ant-menu > .ant-menu-item-open,
.ant-menu > .ant-menu-submenu-open,
.ant-menu > .ant-menu-item-selected,
.ant-menu > .ant-menu-submenu-selected {
  color: #003CFF;
  font-weight: bold;
}

.ant-menu-vertical .ant-menu-item::after,
.ant-menu-vertical-left .ant-menu-item::after,
.ant-menu-vertical-right .ant-menu-item::after,
.ant-menu-inline .ant-menu-item::after {
  border-right: 6px solid #003CFF;
  border-radius: 4px;
}

.ant-menu > .ant-menu-item:not(.ant-menu-item-selected) {
    color:rgba(0, 0, 0, 0.4);
}

.logo {
    margin:16px;
}

.site-layout .site-layout-background {
background: #fff;
}

.full-screen {
    min-height: 100vh;
}

I added width:500px to light-bg class but that doesn't work. Any idea how can I change the width of the Sider component?

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

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

发布评论

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

评论(1

染墨丶若流云 2025-02-01 05:53:40

好的,我弄清楚了,您要做的就是添加一个宽度属性

<Sider width={500} className='light-bg' trigger={null} collapsible collapsed={this.state.collapsed}>

Ok I figured it out all you have to do is add a width attribute to the Sider component tag like this

<Sider width={500} className='light-bg' trigger={null} collapsible collapsed={this.state.collapsed}>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文