Html 如何限制div宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7641195/
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
How to limit div width?
提问by René Houmran Griffin
Its still overflowing it looks like this
它仍然溢出它看起来像这样
<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 />
回答by esqew
<html>
<head>
<style type="text/css">
#limit {
max-width: 500px;
}
</style>
</head>
<body>
<div id="limit">Your content goes here</div>
</body>
</html>
回答by Eray
With max-width. Example : http://jsfiddle.net/YCV8H/
回答by saraf
max-width and width -both- do not prevent the overflow if the text does not contain any spacesas in the example in the question.
如果文本不包含任何空格,则max-width 和 width -both- 都不会防止溢出,如问题中的示例所示。
div {
max-width : 300px;
word-wrap: break-word;
}
see this fiddlefor a solution.
请参阅此小提琴以获取解决方案。
For this case, the div must have the style "word-wrap: break-word" in order to work.
对于这种情况,div 必须具有“ word-wrap:break-word”样式才能工作。
Or "overflow-wrap: break-word"
或“溢出包装:断字”