1

I'm using ng-repeat to display some messages, and I'm trying to make the "message_area" scrollable as the messages naturally cause overflow over time, but my code doesn't work as expected.

<div class="main_area">

  <div id = "message_area" ng-repeat = "message in selected_conversation_object.messages.slice().reverse()">
    <div class="message_container" ng-if = "message.sender != me._id">
      <div class="message_received">{{message.message}}</div>
    </div>
    <div class="message_container" ng-if = "message.sender == me._id">
      <div class="message_sent_by_me">{{message.message}}</div>
    </div>
  </div>

</div>

.main_area {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 325px;
  right: 0;
  height: 100%;
  background: white;
}

#message_area {
  position: relative;
  overflow-y: scroll;
}

.message_container {
  position: relative;
  width: 100%;
  height: 30px;
}

.message_received {
}

.message_sent_by_me {
  position: relative;
  background-color: #0084FF;
  border-radius: 5px;
  width: 100px;
  color: white;
  float: right;
}

I've not been able to understand why my code does not work.

Any suggestions would be appreciated.

2
  • 1
    Please provide a fiddle for your snippet. Commented Dec 26, 2015 at 14:23
  • Provide sample message data. That could help to test run the code. Commented Dec 26, 2015 at 15:02

2 Answers 2

1

You need to set min-height for the #message_area selector.

#message_area {
   position: relative;
   min-height: 50px; // Add This.
   overflow-y: scroll;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use scroll to your .main_area. When the ever the data gets more than the given height it manages it with scroll bar on y-axis.

.main_area {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 325px;
  right: 0;
  height: 100%;
  background: white;
  **overflow-y: scroll;**
}

Working Plunker.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.