Html CSS 菜单字符串不会中断第二行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6976211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:56:27  来源:igfitidea点击:

CSS menu string don't break for second line

htmlcss

提问by mrGott

I have a CSS menu.

我有一个 CSS 菜单。

The problem is that in a ul li a span when I have a long string it doesn't break for the second line, it just continues on one line getting out of the menu.

问题是,在 ul li 跨度中,当我有一个长字符串时,它不会在第二行中断,它只会继续在一行中退出菜单。

Here's my CSS code if you want to take a look at it.

如果你想看一看,这是我的 CSS 代码。

What is the problem here? (i have made a simple menu where it works, but in this case, of a dropdown menu - it doesn't)

这里有什么问题?(我做了一个简单的菜单,它可以工作,但在这种情况下,是一个下拉菜单 - 它没有)

here's the link http://jsfiddle.net/mr_mikey/nR2t6/

这是链接http://jsfiddle.net/mr_mikey/nR2t6/

回答by NGLN

Remove the following style from your CSS:

从您的 CSS 中删除以下样式:

#mainmenu ul ul a {
    white-space: nowrap;
}

回答by monchalve

Could it be that you're using inline span tags instead of block-level div tags? Haven't tried myself but this could have an effect on the way overflow and wrapping is handled. There's also a CSS3 property called "word-wrap" that you could try setting to "break-word".

可能是您使用的是内联 span 标签而不是块级 div 标签吗?我自己还没有尝试过,但这可能会影响溢出和包装的处理方式。还有一个名为“word-wrap”的 CSS3 属性,您可以尝试将其设置为“break-word”。