如何使内联div内容不在换行符中分割

用户名

我里面有一个消息div和一个日期字体。

在此处输入图片说明

但是,如果消息的内容很长,则会在换行符中分割日期。我想做的是,如果没有日期空间,则应该全部放在下一行而不是拆分。

的CSS

.message {
    width:500px;
    white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
    white-space: -pre-wrap;      /* Opera 4-6 */
    white-space: -o-pre-wrap;    /* Opera 7 */
    white-space: pre-wrap;       /* css-3 */
    word-wrap: break-word;       /* Internet Explorer 5.5+ */
    white-space: -webkit-pre-wrap; /* Newer versions of Chrome/Safari*/
    word-break: break-all;
    white-space: normal;
    position:relative;
}
    
.messagecontent {
    display: inline-block;
}
    
.date {
    font-size:11px;
    color:#999;
    padding-left:5px;
}
<!-- HTML -->

<div class="message">
  <div class="messagecontent"></div>
  <font class="date"></div>
</div>

正确的方法是什么?

阿图罗

我认为该日期将需要包含在messagecontent div中。代码:

<div class="message">
    <div class="messagecontent">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis felis eget accumsan aliquet. Mauris semper id tortor et tristique. Cras mi ante, euismod in luctus id, hendrerit vel elit.<div class="date">13:12</div></div>
</div>

并设置为inline-block:

.date {
    font-size:11px;
    color:#999;
    padding-left:5px;
    display: inline-block;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章