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

CSS li标签自动换行失效咨询:子菜单长标题重叠解决方案

Fixing Submenu Long Title Overlap Issue

Hey there! Let's work through this submenu text overlap problem you're facing. It's super common when dealing with multi-column menus, so let's break down why your word-break attempt might not have worked, and what to try next.

First, check your word-break implementation

It looks like your code snippet cuts off mid-property (word-break: bre...), so make sure you're using a valid value. There are two key properties to try here, depending on your content language:

  • word-break: break-all;: Will break text at any character, great for Chinese/Japanese where single characters make sense on their own.
  • overflow-wrap: break-word;: Prefers breaking at word boundaries (better for English, keeps words intact when possible).

But just adding this to the <li> might not be enough—your parent container needs to have a defined width constraint so the browser knows when to wrap the text.

Step-by-Step Fix Example

Let's assume your submenu uses a two-column layout. Here's a complete, tested setup:

<!-- Your submenu structure -->
<ul class="submenu">
  <li class="submenu-column">
    <h3 class="column-title">这是一个超级长的子菜单标题,用来测试文本是否会自动换行而不重叠到旁边列</h3>
    <!-- Menu items here -->
  </li>
  <li class="submenu-column">
    <h3 class="column-title">第二列标题</h3>
    <!-- Menu items here -->
  </li>
</ul>
/* Base submenu layout */
.submenu {
  display: flex;
  gap: 2rem; /* Add space between columns to prevent crowding */
  max-width: 800px; /* Set a max width so columns don't stretch infinitely */
  padding: 0;
  list-style: none;
}

/* Column styling with text wrap */
.submenu-column {
  flex: 1; /* Let columns share available space equally */
  min-width: 200px; /* Prevent columns from getting too narrow */
}

.column-title {
  overflow-wrap: break-word; /* Use this for mixed language content */
  /* Or word-break: break-all; if you need to break anywhere */
  white-space: normal; /* Ensure text isn't forced to stay on one line */
  margin: 0 0 1rem 0;
}

Why Your Previous Attempt Failed

  • Incomplete word-break value: If your code cut off at bre..., the browser ignores the invalid property, so no wrapping happens.
  • No width constraint on parent: Without a max-width or flex basis on the submenu/columns, the <li> will just expand to fit the long text instead of wrapping.
  • Conflicting CSS: Check if other styles (like white-space: nowrap;) are overriding your word-break rules—use browser dev tools to inspect the element's computed styles.

Quick Debug Tip

Right-click the overlapping title in your browser and select "Inspect". Look at the "Styles" tab to confirm:

  1. Is overflow-wrap or word-break actually applied (not crossed out)?
  2. Does the parent <li> or <ul> have a defined width/max-width?

This should help you pinpoint exactly where the issue is!

内容的提问来源于stack exchange,提问作者钟子康

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:10:38