【问题标题】:why long text appears below name?为什么名称下方出现长文本?
【发布时间】:2019-05-27 14:54:29
【问题描述】:

我希望消息从名称的右侧开始,如果它太长,则在下面继续

.. 像第二个文本,但它很短..

php ;

        echo'
            <div class="chatpos">
              <div class="namec">'.$resnamec['username'].'</div>
              <div class="msgc">'.$reschat['message'].'</div>
            </div>';
        }

css ;

  .chatpos {
    position: relative;
    width: 90%;
    min-height: 30px;
    float: right;
}

.namec {
    display: inline-block;
    position: relative;
    text-align: center;
    color: #9aefd8;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    padding-left: 2px;
    padding-right: 2px;
    transition: all 0.3s ease-in-out;
    letter-spacing: 0px;
}

.msgc {
    display: inline-block;
    word-wrap: break-word;
    position: relative;
}

【问题讨论】:

  • 您提供的代码无法复制该问题。请提供显示问题的确切代码

标签: html css block


【解决方案1】:

msgc 类设置为display: inline-block。相反,它应该设置为display: inline。像这样:

.msgc {
  display: inline;
}

检查this fiddle 看看这是否是您想要的。


事后看来,我认为更可靠的方法是将msgcnamec 都设置为display: block。此外,您可以将namec 设置为float: left,如下所示:

.namec {
    display: block;
    float: left;
    margin-right: 5px;
    color: blue;
}

.msgc {
    display: block;
    text-align: justify;
}

检查this updated fiddle

【讨论】:

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