display:table-cell vertical-align:bottom.
Sotiris CSS.
HTML
<div style="display:table; height:200px;">
<div style="display:table-row">
<div id="chat" style="width:400px; border:1px solid black;display:table-cell; vertical-align:bottom">
</div>
</div>
</div>
<input type="text"><input type="button" value="post">
JavaScript
$(':button').click(function() {
var message = $('input[type=text]').val();
$('#chat').append( $('<div/>').text(message) );
});
, , .
fiddle
I continued to search for the best solution, because the table layout is always suspicious for me, but I found an article css-tricks about it, and they do the same as I do .. so I think this solution is the right one.
ADD - save scrolling to lower code
As new messages come from the bottom, we need to keep the scroll down. I updated the fiddle link
source
share