html - 为什么名字下面会出现长文字?

标签 html css block

enter image description here

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

.. 和第二个文本一样,但它很短..

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;
}

最佳答案

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 .

关于html - 为什么名字下面会出现长文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56328366/

相关文章:

css - firefox 上的第 n 个 child

c++ - GNU radio : How to define a "get_*" method inside a sink block

iOS GCD 与异步 block 同步

php - mysql从具有多个提交按钮的列表中插入

javascript - 文档底部编写的代码总是在 DOM 准备好之后执行吗?

php - 从mysql获取日期和时间输出到html表中

javascript - DIV 中的文本对齐(TEXT 没有空格)

javascript - Bootstrap float 面板

CSS左侧菜单布局问题

Ruby 异步网络::HTTP?