文本溢出时包含div的断行

时间:2011-07-23 18:19:39

标签: html

我有这样的代码:

<div>
    <ul>
        <li>This my text but it is too long and it is stick out from div becaue it has too many characters. And i want it text to break somewhere, beste break it in place where is blank character.</li>
    <ul>
</div>

我希望自动完成这样的事情:

    <div>
        <ul>
            <li>This my text but it is too long and it is stick out from div 
                becaue it has too many characters. And i want it text to break
                somewhere, beste break it in place where is blank character.
            </li>
        <ul>
    </div>

我可以在html和css中执行此操作,还是需要其他内容,也许是javascript?如果我能做到这一点,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

你需要在你的css文件中为你的li赋予宽度:

li
{
        width:150px;
}

或者像这样:

<div>
    <ul>
        <li style="width:150px;">This my text but it is too long and it is stick out from div becaue it has too many characters. And i want it text to break somewhere, beste break it in place where is blank character.</li>
    <ul>
</div>

看看这个:http://jsfiddle.net/qqzaK/1/