我正在使用角度和引导程序进行练习聊天应用程序。 试图让div边框环绕文本,如iPhone消息气泡, 内联块似乎不起作用。
相关代码:
<div class="col-md-4 chatWindow">
<div ng-show="activeFriend">
<div class="activeFriendBox">Chat with {{activeFriend.name}}</div>
<div class="messageList">
<div class="messages"
ng-class="{ 'message-right': message.from === currentUser, 'message-left': message.from !==currentUser }"
ng-repeat='message in activeFriend.messages track by $index | orderBy:"timeStamp"'>
<span>{{message.from}}</span>
<span>{{message.message}}</span>
</div>
</div>
<div class="sendMessage">
<form ng-submit='sendMessage(messageText)' name='messageForm'>
<input type='text' name='message' ng-model='messageText' required/>
<input ng-disabled='!messageForm.$valid' type='submit' value='send'/>
</form>
</div>
</div>
</div>
CSS:
.messages {
border: 1px solid black;
border-radius: 15px;
/*display: inline-block;*/
}
.message-right {
text-align: right;
}
.message-left {
text-align: left;
}
答案 0 :(得分:0)
你必须左右浮动包含div,然后清除每个div。
HTML:
<div class="col-md-4 chatWindow">
<div class="activeFriendBox">Chat with {{ activeFriend.name }}</div>
<div class="messageList">
<div class="messages message-right">
<p>Message from 1</p>
<p>Message 1</p>
</div>
</div>
<div class="messageList">
<div class="messages message-left">
<p>Message from 2</p>
<p>Message 2</p>
</div>
</div>
<div class="sendMessage">
<form ng-submit='sendMessage(messageText)' name='messageForm'>
<input type='text' name='message' ng-model='messageText' required/>
<input ng-disabled='!messageForm.$valid' type='submit' value='send'/>
</form>
</div>
</div>
CSS:
.messages {
border: 1px solid black;
border-radius: 15px;
display: inline-block;
}
.message-right {
clear: both;
float: right;
}
.message-left {
clear: both;
float: left;
}
.sendMessage {
clear: both;
}
.col-md-4 {
width: 33%;
}
答案 1 :(得分:0)
没关系,我想通了,我不得不把内联块放在div内的跨度而不是div本身
答案 2 :(得分:0)
HTML
<div class="col-md-4 chatWindow">
<div ng-show="activeFriend">
<div class="activeFriendBox">Chat with {{activeFriend.name}}</div>
<div class="messageList">
<div class="message-wrap"
ng-class="{ 'message-right': message.from === currentUser, 'message-left': message.from !==currentUser }"
ng-repeat='message in activeFriend.messages track by $index | orderBy:"timeStamp"'>
<div class="message">
<span>{{message.from}}</span>
<span>{{message.message}}</span>
</div>
</div>
</div>
<div class="sendMessage">
<form ng-submit='sendMessage(messageText)' name='messageForm'>
<input type='text' name='message' ng-model='messageText' required/>
<input ng-disabled='!messageForm.$valid' type='submit' value='send'/>
</form>
</div>
</div>
</div>
CSS
/* Represents row (block you wanted) */
.message-wrap {
margin-bottom: 10px;
}
/* Represents message */
.message {
border: 1px solid black;
border-radius: 15px;
display: inline-block;
}
.message-right {
text-align: right;
}
.message-left {
text-align: left;
}