Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在没有滚动的情况下将长文本包装在div中 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921........._Html_Css - Fatal编程技术网

Html 如何在没有滚动的情况下将长文本包装在div中 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........

Html 如何在没有滚动的情况下将长文本包装在div中 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........,html,css,Html,Css,上面的代码显示了一个长滚动条。我想将其保持在div声明的宽度内(width:200px;),而不滚动。 我尝试过浮动、显示、定位、溢出,但在这里没有任何效果。尝试使用这些CSS规则 <div style="width:200px; margin:0 auto;"> 012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596

上面的代码显示了一个长滚动条。我想将其保持在div声明的宽度内(
width:200px;
),而不滚动。
我尝试过浮动、显示、定位、溢出,但在这里没有任何效果。

尝试使用这些CSS规则

<div style="width:200px; margin:0 auto;"> 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........
</div>
试试这个:-

 white-space: nowrap;      //keep the text on one line
 overflow: hidden;         //prevent the text from being shown outside the border
 text-overflow: ellipsis;  //cut off text with an elipsis

演示:

使用
文本溢出:省略号

完整说明:

01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........

jsiddle:

您可以使用
溢出包装:break-word。也要避免内联样式

css

<div style="width:200px; margin:0 auto; word-wrap:break-word;">    01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921.........
</div>
试试这个:

div{
    width: 200px;
    margin: 0 auto;
    overflow-wrap: break-word;
    word-wrap: break-word; /* Firefox support */
}
注意:避免
inline
样式


对于我来说,我的div在一个可滚动的父div中,只需添加到您的子div或content div即可

div {
    width:200px;
    margin:0 auto;
    white-space: pre-wrap;      /* CSS3 */   
    white-space: -moz-pre-wrap; /* Firefox */   
    white-space: -o-pre-wrap;   /* Opera 7 */    
    word-wrap: break-word;      /* IE */
}

这将强制将内容拆分为多行。@Ibrahimashshoail好吧,OP没有指定如何处理文本,无论是换行到下一行,还是在后面加上省略号或是什么。这就是我发表评论的原因。以便他了解CSS位的效果。:)@易卜拉欣:啊,明白了。我刚刚看到一个快速的否决票,然后你的评论进来了。我以为你是个混蛋PDo是否希望文本换行到两行或更多行?请澄清。@MarcAudet-是的,我需要所有文本,但在“200px”的宽度内,实际内容是什么?一个无意义的数字串,后跟句点,前面有空格?绳子可能断裂的允许点是什么?这在很大程度上取决于内容及其上下文,作为一个抽象问题,这要么“不清楚你在问什么”要么“太宽泛”(如果一个问题涵盖了十几个常见场景,那么答案对于SO格式来说就太长了)。
overflow wrap
在FireFox中不完全受支持
wordwrap
得到了更好的支持。是的,对于firefox使用
wordbreak:breakall
换行:断开单词
div {
    width:200px;
    margin:0 auto;
    white-space: pre-wrap;      /* CSS3 */   
    white-space: -moz-pre-wrap; /* Firefox */   
    white-space: -o-pre-wrap;   /* Opera 7 */    
    word-wrap: break-word;      /* IE */
}
    div{
        white-space: normal;
        }

OR

    div{
    white-space: pre-wrap;
    }