Search code examples
htmlcssblock

why long text appears below name?


enter image description here

I want the message begin at the right from the name and continue below if its too long

.. like the second text but its short ..

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

Solution

  • The msgc class is set to display: inline-block. Instead, it should be set to display: inline. Like so:

    .msgc {
      display: inline;
    }
    

    Check this fiddle to see if this is what you desired.


    In hindsight, I believe a more reliable approach would be to set both msgc and namec to display: block. Additionally, you may set namec to float: left, like this:

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

    Check this updated fiddle.