Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Text overlapping issue

So I am creating a a web chat and I am trying to set up my message timestamp to be a little more up.. meaning that the margins are overlapping. I am not sure how to set my text div to be wide enough so the timestamp doesn’t overlap with actual message text.

.message-box {
  background-color: #7facd3;
  align-self: flex-start;
  border-radius: 0.5rem;
  color: black;
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: 85%;
  margin: 3px 10px 0 10px;
  padding: 5px;
}

.message-text {
  margin-top: 4px;
  text-align: left;
  width: fit-content;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.timestamp-div {
  display: block;
  align-self: flex-end;
  margin: -11px 0 0 0;
  width: min-content;
  line-height: 15px;
  padding: 0;
  font-size: 11px;
  font-weight: 300;
}
<div class='message-box'>
  <span class='username'>Aleks</span>
  <div class='message-text'>Message.</div>
  <div class='timestamp-div'>14:56</div>
</div>

Current situation:

Current situation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add margin-right: -30px; to timestamp-div and padding-right: 35px to message-box.

    .message-box {
        background-color: #7facd3;
        align-self: flex-start;
        border-radius: 0.5rem;
        color: black;
        display: flex;
        flex-direction: column;
        width: min-content;
        max-width: 85%;
        margin: 3px 10px 0 10px;
        padding: 5px;
        padding-right: 35px;
    }

    .message-text {
        margin-top: 4px;
        text-align: left;
        width: fit-content;
        word-wrap: break-word;
        white-space: pre-wrap;
    }

    .timestamp-div {
        display: block;
        align-self: flex-end;
        margin: -11px 0 0 0;
        width: min-content;
        line-height: 15px;
        padding: 0;
        font-size: 11px;
        margin-right: -30px;
        font-weight: 300;
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading