You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将菜单中User Access and Control management system标题拆分为两行?

导航菜单标题换行实现方案

你的原始导航配置代码如下:

{
    id: uniqueId(),
    title: 'User Access and Control management system',
    icon: FaUsers,
    href: '/systems/userAccess/',
    children: [
      {
        id: uniqueId(),
        title: 'System Access',
        icon: IconPoint,
        href: '/systems/userAccess/UserAccess',
      },
    ],
  },

要让标题显示为两行,可根据你使用的UI框架和渲染环境选择以下方案:

方案1:使用HTML换行符 <br>

直接在title字符串中插入<br>,前提是你的菜单组件支持渲染HTML内容:

{
    id: uniqueId(),
    title: 'User Access and Control<br>management system',
    icon: FaUsers,
    href: '/systems/userAccess/',
    children: [
      {
        id: uniqueId(),
        title: 'System Access',
        icon: IconPoint,
        href: '/systems/userAccess/UserAccess',
      },
    ],
  },

如果组件默认不解析HTML,需要开启对应配置(比如React中使用dangerouslySetInnerHTML包裹标题内容)。

方案2:通过CSS强制换行

给菜单标题元素添加CSS样式,配合字符串中的换行符\n实现换行:

  1. 给标题元素添加样式:
.menu-title {
  white-space: pre-line; /* 识别换行符并换行 */
  /* 或者设置固定宽度,让文本自动换行 */
  /* width: 150px; */
}
  1. 修改title字段,插入\n:
{
    id: uniqueId(),
    title: 'User Access and Control\nmanagement system',
    icon: FaUsers,
    href: '/systems/userAccess/',
    children: [
      {
        id: uniqueId(),
        title: 'System Access',
        icon: IconPoint,
        href: '/systems/userAccess/UserAccess',
      },
    ],
  },

方案3:使用JSX(React环境)

如果是React项目,直接将title设置为JSX元素,自由控制换行结构:

{
    id: uniqueId(),
    title: (
      <span style={{ whiteSpace: 'pre-line' }}>
        User Access and Control
        management system
      </span>
    ),
    icon: FaUsers,
    href: '/systems/userAccess/',
    children: [
      {
        id: uniqueId(),
        title: 'System Access',
        icon: IconPoint,
        href: '/systems/userAccess/UserAccess',
      },
    ],
  },

也可以用<br/>标签替代换行,效果一致。

内容的提问来源于stack exchange,提问作者Chooty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 05:42:18