Reputation: 181
I have looked at several solutions to this question but none of them work for me. I am appending a paragraph to a div and the text goes out of the element. Here is my code. Please help.
CSS:
chat-h {
margin-left: 7px;
width: 249px;
background: red;
}
#chat-p {
width: 150px;
background-color: #fff;
word-wrap: break-word;
}
.msg span {
font-weight: bold;
color: blue;
}
and JQuery
function appendMsg(user, msg) {
var $cont = $("#chat-h");
$cont[0].scrollTop = $cont[0].scrollHeight;
$cont.append("<p class='msg' id='chat-p'><span>" + user + ": </span> " + msg + " </p>");
}
Upvotes: 1
Views: 8648
Reputation: 81
Use the white-space
and overflow
properties:
#chat-p {
width: 150px;
background-color: #fff;
white-space: nowrap; /* or `pre` */
overflow: hidden;
}
And (optionally) add hellip at the end of line:
text-overflow: ellipsis;
Upvotes: 0