【问题标题】:How to to get my text to wrap within a div?如何让我的文本包含在 div 中?
【发布时间】:2011-01-03 19:21:59
【问题描述】:

#word {
  font-weight: bold;
  width: 20px;
  height: 100%;
  background-color: #0f3039;
}

#answer {
  width: 285px;
  height: 25px;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 10px;
  padding-top: 15px;
  background-color: #0f3039;
  margin-left: 348px;
  font-size: 16px;
  margin-top: 0px;
}
<div id="answer" style="display:none;">
  Go With: <span id="word"></span>
</div>

我试图让文本保持在边界内,但它没有正确换行。不确定需要更改什么。

【问题讨论】:

    标签: html css text word-wrap


    【解决方案1】:

    尝试white-space 可能的值

    
    white-space: none;
    white-space: nowrap;
    white-space: pre;
    white-space: pre-wrap;      
    white-space: pre-line;      
    white-space: inherit;
    

    【讨论】:

      【解决方案2】:

      您正在使用 span,它是一个内联元素。在内联 elemnet 上,您不能设置宽度。

      改成display: block;

      查看小提琴:http://jsfiddle.net/zasDb/1/

      甚至更好display: inline-block;

      但是不知道IE是否支持这个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多