如何限制div宽度?

Ren*_*fin 7 html width

它仍然溢出它看起来像这样

<table id="hlavni" style=" position:absolute; border:none; position:relative; background-color:#FFC; border:#999 1px solid;" cellpadding="5">
                <tr>
                <td id="yamana" class="trida" valign="top" style="line-height:1.5em;"><div style="background-color:#FFC;" id=load_tweets>44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444</div>
        </td>
        </tr></table><br />
Run Code Online (Sandbox Code Playgroud)

esq*_*qew 9

<html>
<head>
    <style type="text/css">
    #limit {
        max-width: 500px;
    }
    </style>
</head>
<body>
    <div id="limit">Your content goes here</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

  • 甚至只是`width:500px`. (2认同)

sar*_*raf 5

如果文本不包含任何空格(如问题中的示例所示),则max-width 和 width -both- 不会防止溢出。

div {
    max-width : 300px;
    word-wrap: break-word;
}
Run Code Online (Sandbox Code Playgroud)

请参阅此小提琴以获取解决方案。

对于这种情况,div 必须具有“ word-wrap:break-word ”样式才能工作。

或者“溢出换行:断字